Popup shown in backgroundworker thread

Sep 21 2008 4:42 AM

I have a form 'frmProgressBar', which is shown as popup using obj.showDialog(). This form has a backgroundworker thread running, which keeps running till the processing in other forms is not compleated. I want to hide this form whenever the main form is minimised and this form is getting hidden also. But the problem is, when the main window is maximized, I want to show the  popup form again. I checked !IsDestroyed which returns false, so the thread is still running, but the form is not displayed in the foreground. I tried Show(), BringToFront(), TopLayer = True, but nothing seems to work. Any hellp please.It is very urgent.

bool bContinue = true;

 

public frmProgressBar(string Message)

{

InitializeComponent();

this.ShowInTaskbar = false;

lblMessage.Text = Message ;

backgroundWorker = new BackgroundWorker();

backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);

backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

}

 

//This is called when my main window is resized

private void setWindowStateAccordingToMainForm(FormWindowState State)

{

if (this.InvokeRequired)

{

setWindowState d = new setWindowState(setWindowStateAccordingToMainForm);

this.Invoke(d, new object[] { State });

}

else

{

if ((State == FormWindowState.Maximized) || (State == FormWindowState.Normal))

{

if (!this.IsDisposed)

{

WindowState = FormWindowState.Minimized;

Show();

}

}

else if (State == FormWindowState.Minimized)

{

if (!this.IsDisposed)

{

WindowState = FormWindowState.Minimized;

Hide();

}

}

}

}

 

void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

{

this.Close();

this.Dispose();

}

 

void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)

{

while (bContinue)

{

}

}

Thank You,