sooprise
sooprise

Reputation: 23177

WinForm Refreshing Issue

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.

Upvotes: 1

Views: 138

Answers (2)

VOX
VOX

Reputation: 2923

this.Visible = false; 
MethodInvoker mk = delegate {
Kill.Zombies(); this.Close();
};
mk.BeginInvoke(null,null);

use above code.

Upvotes: 2

Gabriel Magana
Gabriel Magana

Reputation: 4526

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.

Upvotes: 5

Related Questions