If you don't need interactivity, stay away from multithreading -- it isn't
necessary. Simply add a call to Refresh() after you update the label text:
Label label;
label.Text = "Processing record " + rec_num.ToString();
label.Refresh();
If you need interactivity w/ your user interface (e.g. you need to allow the
user to cancel the operation mid-stream), you either have to resort to running
the processing in a background thread (i.e. multithreaded) or occasionally
allow messages to be processed (not multi-threaded):
for (/* main processing loop*/)
{
// do one iteration of work
// process any pending messages
// Note: this uses the Win32 api, convert to .NET
while (PeekMessage(..., PM_REMOVE))
{
TranslateMessage(...);
DispatchMessage(...);
}
// break out if user pressed cancel
if (cancel_operation)
{
break;
}
}
Dig?
Ken Saganowski wrote:
Does anyone have any sample code for a multi threaded form that refreshes
itself while an extended operation is executing:
Example: I am updating a local dataset which could potentially have 1000's
of records. I would like to update a label in the meantime but the problem
is that the form seems to be locked while this operation is executing.
Any advice would be greatly appreciated.
--
Bret Pehrson
mailto:br**@infowest.com
NOSPAM - Include this key in all e-mail correspondence <<38952rglkwdsl>>