ShowDialog method not showing the popup in foreground

Sep 22 2008 11:07 AM
I have a form 'frmProgressBar', which is shown as popup using objfrmProgressBar.showDialog() from a class AppGlobals (AppGlobals.prpgressbar.show() method). frmProgressBar has a backgroundworker thread running, which keeps running till the processing in other forms is not compleated. I want to hide popup whenever the main form, on which other controls are loaded, is minimised and the popup is getting hidden also. But the problem is, when the main form is maximized, I want to show the popup form again. I checked !IsDestroyed for frmProgressBar which returns false, so the backgroundworker thread is still running, but the popup is not displayed in the foreground, only main form is shown. I tried Show(), BringToFront(), TopLayer = True, but nothing seems to work. I can't set Owner property of the form frmProgressbar becuase of some design constraints. Any help please.It is very urgent.

Following is my code :

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 event us fired
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.Maximized;
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)
{
}
}