The whole program freeze and gray like enabled false i can't click on it do nothing only close it from the visual studio Stop Debugging.
It started once after i added: protected override void OnFormClosing
bool mCompleted = false;
bool mClosePending = false;
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (!mCompleted)
{
backgroundWorker1.CancelAsync();
this.Enabled = false;
e.Cancel = true;
mClosePending = true;
return;
}
base.OnFormClosing(e);
}
I added this override since i wanted to make sure the backgroundworker i'm using was stop before closing the form1 when i click the right top x. So it is working while the backgroundworker is running but when the backgroundworker is not running i just run the program and click the x then the whole program is like enabled false and all i can do is shut it down by stop debugging.
In backgroundworker completed event i did:
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled == true)
{
}
if (e.Error != null)
{
}
else
{
mCompleted = true;
if (mClosePending) this.Close();
}
}
But the problem happen when the backgroundworker is not running and i just click the x.