I wrote a small method to take a delegate as parameter and call BeginInvoke if InvokeRequired is true but that function doesn't get called.
Function:
void CallInvokeIfRequired(Action func)
{
if (this.InvokeRequired)
this.BeginInvoke(func);
else
func();
}
I'm using like this:
BackgroundWorker bw = new BackgroundWorker();
loadingOperation loadingForm = new loadingOperation();
bw.DoWork += delegate
{
CallInvokeIfRequired(delegate
{
MessageBox.Show("lol!");
Thread.Sleep(1000 * 3);
loadingForm.Show();
// some stuff herere
});
};
bw.RunWorkerCompleted += delegate
{
CallInvokeIfRequired(delegate
{
loadingForm.Close();
});
};
bw.RunWorkerAsync();
What's wrong and how do I fix it?
Aucun commentaire:
Enregistrer un commentaire