Non-modal dialog

  • Thread starter Thread starter Xarky
  • Start date Start date
X

Xarky

Hi,
I have a window, where for a certain event(button click), I am
starting a new thread. This thread is retrieving data, creating a new
window and displaying it.

The window is being shown by "name.Show();". As the window is being
opened, it is being closed immediately. I know that I can use the
ShowDialog() method, but that would block the execution of the other
thread till the other terminates.

****event****
Thread x = new Thread(new ThreadStart(myMethod));
x.Start();

myMethod()
{
.... Doing some execution

messageWindow.Show();

.... I would like this to contine to live until window is closed,
.... and the other window(main) to contine operate on its own.
}


Can someone help me out.
Thanks in Advance
 
Hi!
Try to create the method myMethod in the class form which you want to dispay
as modal like below:
using (MessageWindow messageWindow = new MessageWindow())
{
...
Thread x = new Thread(new ThreadStart(messageWindow.myMethod));
messageWindow.ShowDialog();
...
}

I'm not sure that is what you want.
Best regards.
 
Hi,
I used the method told. The problem seems to keep persisting, and I
can do nothing on the other thread till the messageWindow dialog
terminates.

I tried to put the messageWindow.ShowDialog() in myMethod(), but that
gave an error
'An unhandled exception of type 'System.ObjectDisposedException'
occurred in system.windows.forms.dll

Additional information: Cannot access a disposed object named
"MessageWindow".'

I also tried to start of the messageWindow.ShowDialog() in another
thread, so that this new thread will block, and leave the main thread
free, but that gave the same error.
 
If your thread is a worker thread then shouldn't it just work? and then once
it has gathered the information, it should notify your main window and the
main window should show the other window (modelessly)
 
The solution was very simple, that the things I started complicated. I
just put everything on the worker thread, and used ShowDialog. When it
returns, worker thread returns and so main thread is not effected.

Thanks for all your help, and sorry if I did not explain myself well,
since it seems that not even me knew what I was doing :S
 
Back
Top