tags:

views:

39

answers:

2

I have a program that can open multiple forms, and when there are a lot of them, they cascade when they are opened.

When a button is pressed, some code runs and the form closes

this.Visible = false; Kill.Zombies(); this.Close();

My Kill.Zombies(); method takes a few seconds to run, so I make the form invisible before running it. The problem I'm having is that even when it's invisible, the forms behind it don't refresh, and it's as if the form that should be invisible is still visible.

I try moving the form before making it invisible, and it still has the issue of showing up on top of forms behind it.

If you could give me some advice on how to fix this, I'd appreciate it.

+4  A: 

Do you call Application.DoEvents() after this.Visible = false; ?

The proper way to do it would be multithreaded, but a call to DoEvents() might fix it.

gmagana
Updated my answer at the same time you posted, lol, thanks
gmagana
Yes, this is correct answer, I understand question wrong.
Serkan Hekimoglu
Why not add some code showing the proper way as well (either using a `ThreadPool` or a `BackgroundWorker`)?
Daniel Pryden
This worked perfect. Saved me a headache for sure!
Soo
@Daniel: Because that's not the question. The question is how to fix the display errors, which I answered.
gmagana
I think your solution will work most of the time but there can be times that won't work. Like it'll make the form invisible for 100 times but not 101. As @Daniel said the proper way is to use threading.
VOX
+2  A: 
this.Visible = false; 
MethodInvoker mk = delegate {
Kill.Zombies(); this.Close();
};
mk.BeginInvoke(null,null);

use above code.

VOX