Main Thread calls a new Thread. How Do I Synchronise when new thread is finished?
Posted on 2009-06-29
Im developing a windows application (not Internet based) using Visual Studio 2008 and Visual C#.
The application basically reads the output from some hardware then processes the information and draws graphs etc. The part where it reads infomation from the hardware can take up to ten minutes and basically locks up the computer. I want to have this bit in a separate thread so it can be aborted if necessary and so the computer can do other things.
When the user clicks a button the following code is executed on the Main Thread.
'threadTask' is the function that reads from the hardware and is the executed from the new thread.
Thread trd = new Thread(new ThreadStart(this.threadTask));
trd.IsBackground = true;
Now when this function finishes I want this thread to basically end and another function (that processes the information) to start executing. This function (lets call it Process) should in the Main thread.
How do I synchronise so that the function Process on the Main thread is executed when the thread I created to read from the hardware (the function threadTask) is finished?
Note all the data is stored in class variables so I dont need to send data as function arguments etc.