|
-
April 15th, 2008, 08:08 AM
#1
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.
-
April 15th, 2008, 08:24 AM
#2
Re: Background not repainting
Calling Application.DoEvents is the simplest method.
-
April 15th, 2008, 12:52 PM
#3
Re: Background not repainting
Creating a thread for your methods that run a long time is the proper way.
-
April 15th, 2008, 01:12 PM
#4
Re: Background not repainting
 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
}
-
April 16th, 2008, 06:09 AM
#5
Re: Background not repainting
Thank you all for the replies.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|