Click here to Skip to main content
15,887,027 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionAccessing control from a different thread Pin
piul14-Feb-11 23:18
piul14-Feb-11 23:18 
AnswerRe: Accessing control from a different thread Pin
piul14-Feb-11 23:41
piul14-Feb-11 23:41 
AnswerRe: Accessing control from a different thread Pin
Simon_Whale14-Feb-11 23:59
Simon_Whale14-Feb-11 23:59 
AnswerRe: Accessing control from a different thread Pin
Luc Pattyn15-Feb-11 3:14
sitebuilderLuc Pattyn15-Feb-11 3:14 
QuestionExternal process stops everything else Pin
piul14-Feb-11 0:31
piul14-Feb-11 0:31 
AnswerRe: External process stops everything else Pin
Luc Pattyn14-Feb-11 1:06
sitebuilderLuc Pattyn14-Feb-11 1:06 
GeneralRe: External process stops everything else Pin
piul14-Feb-11 2:25
piul14-Feb-11 2:25 
GeneralRe: External process stops everything else Pin
Luc Pattyn14-Feb-11 2:37
sitebuilderLuc Pattyn14-Feb-11 2:37 
OK, that is quite wrong for several reasons:

1.
the while loop has no blocking calls, so it will spin at full speed, consuming all cycles of one (perhaps the only) core. If you must have a polling loop like that, at least slow it down by inserting say Thread.Sleep(100);
However it is in general better to avoid a polling loop.

2.
It is not OK to halt the main thread like that, as the whole GUI will freeze. If e.g. another window pops up on top of your app, and then goes away again, your app won't repaint itself.

The correct approach would be:
- to have a separate thread (I suggest a BackgroundWorker) which launches the process, captures its output, and waits for its termination;
- to launch this thread from your button click handler (possibly also disabling said button, turning the cursor into a wait cursor, etc);
- to have a delegate dealing with intermediate results (maybe showing them in a ListBox);
- to have another delegate dealing with the termination of the process (restoring the GUI back to normal).

BTW: said thread would not need a polling loop on superMinerProcess->HasExited, as it could use superMinerProcess->WaitForExit()

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

GeneralRe: External process stops everything else Pin
piul14-Feb-11 4:34
piul14-Feb-11 4:34 
AnswerRe: External process stops everything else Pin
Luc Pattyn14-Feb-11 4:43
sitebuilderLuc Pattyn14-Feb-11 4:43 
GeneralRe: External process stops everything else Pin
piul14-Feb-11 5:08
piul14-Feb-11 5:08 
GeneralRe: External process stops everything else Pin
Luc Pattyn14-Feb-11 5:51
sitebuilderLuc Pattyn14-Feb-11 5:51 
GeneralRe: External process stops everything else Pin
piul14-Feb-11 5:59
piul14-Feb-11 5:59 
QuestionInfinite recursion wont go away. Pin
Herboren13-Feb-11 13:27
Herboren13-Feb-11 13:27 
AnswerRe: Infinite recursion wont go away. Pin
Dave Kreskowiak13-Feb-11 15:38
mveDave Kreskowiak13-Feb-11 15:38 
AnswerRe: Infinite recursion wont go away. Pin
Luc Pattyn14-Feb-11 1:10
sitebuilderLuc Pattyn14-Feb-11 1:10 
JokeRe: Infinite recursion wont go away. Pin
musefan14-Feb-11 5:15
musefan14-Feb-11 5:15 
GeneralRe: Infinite recursion wont go away. Pin
Henry Minute14-Feb-11 5:24
Henry Minute14-Feb-11 5:24 
JokeRe: Infinite recursion wont go away. Pin
musefan14-Feb-11 5:44
musefan14-Feb-11 5:44 
GeneralRe: Infinite recursion wont go away. Pin
Henry Minute14-Feb-11 5:49
Henry Minute14-Feb-11 5:49 
GeneralRe: Infinite recursion wont go away. Pin
musefan14-Feb-11 6:04
musefan14-Feb-11 6:04 
QuestionClick on the hyperlink and become an alert icon and also save to database Pin
Peggie199013-Feb-11 12:53
Peggie199013-Feb-11 12:53 
QuestionHow to Detect Music Device Pin
Pranit Kothari11-Feb-11 19:15
Pranit Kothari11-Feb-11 19:15 
AnswerRe: How to Detect Music Device - Repost Pin
Richard MacCutchan11-Feb-11 21:10
mveRichard MacCutchan11-Feb-11 21:10 
QuestionsessionState Pin
MWRivera11-Feb-11 6:43
MWRivera11-Feb-11 6:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.