I'm using a backgroundworker for showing a loadingscreen.
The DO-event looks as follow:
private void bwLoadingScreen_DoWork(object sender, DoWorkEventArgs e)
{
_ls = new LoadingScreen();
_ls.Show();
while (!bwLoadingScreen.CancellationPending)
{
Application.DoEvents();
}
}
I use the following code to Dispose the Loadingscreen:
if (_ls.InvokeRequired && !_ls.IsDisposed)
{
Invoke(new MethodInvoker(delegate
{
_ls.Close();
_ls.Dispose();
}));
}
else if (!_ls.IsDisposed)
{
_ls.Hide();
_ls.Dispose();
}
Should I use the RunWorkerCompleted event for this? Is this the right way to use the Backgroundworker?