Question Sleeping threads

joshuadeboer

Well-known member
Joined
May 28, 2008
Messages
45
Location
Hillsboro, OR
Programming Experience
1-3
Hi,
I'm trying to sleep a single thread of code,
when i try using System.Threading.Thread,
it freezes the whole app,
i need it to just freeze a portion of code. :confused:
 
You need to create a secondary thread, check into the classes BackgroundWorker, ThreadPool and Thread for how to do worker threads. I would read some general multi-threading tutorials also.
 
You some times have to do that, some times not. If you need to retrieve values from controls that the worker will process you can (and should) most likely get these values before starting the work and pass them on to the worker, usually with the RunWorkerAsync(Object) method. If you need to access the controls to report any kind of progress you can use the ProgressChanged and RunWorkerCompleted events of the Bgw, no need to Control.Invoke for this as these events are raised on UI thread. Learning how to invoke is still very useful to learn.
 
I'm trying to get and set values, mainly from a ListView control.

JuggaloBrotha's link didn't work (not signed up with Experts Exchange.:D

Please post any links you know of for cross-threading or Control.Invoke.

Thanks a lot!
 
Quick and Dirty ... you can use the Background Workers "ReportProgress" Event. This event runs in the context of the calling thread and an "object" can be passed.

Usually I use "PercentProgress" as selector in a select case statement inside that handler and depending on the code in side, I cast the object accordingly.
 
Back
Top