Simple Threading Question
Dear Gurus,
I am running some lengthy calculations and attempt to provide some feedback from it in the dialog via showing the iteration number, elapsed time, etc, my "calculation" program looks like this:
void CalcProgram()
{
...
Thread MyProgress = new Thread(new ThreadStart(MyUpdate));
// Start the thread
MyProgress.Start();
for(i=0; i<IterationNumber; i++)
{
...// Long calcuations
...
MessageBox.Show("I am here");
}
}
When I run the program and comment out the MessageBox shown, the thread seem to be not working, i.e. it does not provide the expected output. However, when the message box is there, the thread seem to be working as expected only when the box is shown, when I click "OK" on the box it does not provide any updates until the MessageBox is shown again.
Does anybody knows why????
Thank you.
Re: Simple Threading Question
I'm far from being an "guru" on threads, but have you considered using a BackgroundWorker class instead?
Basically it is a thread with some extra functionality that might help you out.
Here is some explanation and example: http://www.albahari.com/threading/part3.aspx
If you want to report something else than just a percentage with the BackgroundWorker, you can use the UserState object parameter to pass just about anything you want and then cast it for your original data.
Re: Simple Threading Question
With no code we can't tell you what you've done wrong...