Background not repainting
I have written an app in c# that autoarchives our system files to a sourcesafe database. Some of these actions can take a while and the main form becomes white with no controls drawn. After the operation has completed the controls get redrawn but not the forms background. I have tried an invalidate but this does nothing. Can anyone tell me why the form goes blank in the first place and how to repaint the background.
Thanks.
Re: Background not repainting
Calling Application.DoEvents is the simplest method.
Re: Background not repainting
Creating a thread for your methods that run a long time is the proper way.
Re: Background not repainting
Quote:
Originally Posted by crackersixx
Creating a thread for your methods that run a long time is the proper way.
Yep, the simplest way being using a BackgroundWorker. Very easy to use for simple threading. Just remember to wrap any UI changes in the following:
Code:
controlToChange.Invoke((MethodInvoker)delegate()
{
//controlToChange.Text = "whatever";
// UI changes here
});
And the BackgroundWorker stuff itself:
Code:
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync();
void bw_DoWork(object sender, DoWorkEventArgs e)
{
// do stuff
}
Re: Background not repainting
Thank you all for the replies.