Threading problem
-
Dear all, I've written a method which I call from a thread. The problem is that it opens the form in the method, as it is suppose to, but it closes the form immediately after it opened it. Any hints ? here's the code :
void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { Thread thread = new Thread(OpenMethod); thread.Name = "something"; thread.Start(); //thread.Join(); } private void OpenMethod() { if (_form == null) { _form = new NewForm(); _form.Closed += new EventHandler(_form_Closed); } _form.WindowState = FormWindowState.Normal; // bring it from the taskbar if necessary _form.Show(); }
Kind regards, -
Dear all, I've written a method which I call from a thread. The problem is that it opens the form in the method, as it is suppose to, but it closes the form immediately after it opened it. Any hints ? here's the code :
void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { Thread thread = new Thread(OpenMethod); thread.Name = "something"; thread.Start(); //thread.Join(); } private void OpenMethod() { if (_form == null) { _form = new NewForm(); _form.Closed += new EventHandler(_form_Closed); } _form.WindowState = FormWindowState.Normal; // bring it from the taskbar if necessary _form.Show(); }
Kind regards, -
You calling a UI method on a non-UI thread, look at the Output console. An exception should be waiting for you.
xacc.ide - now with IronScheme support
IronScheme - 1.0 alpha 2 out now -
Dear all, I've written a method which I call from a thread. The problem is that it opens the form in the method, as it is suppose to, but it closes the form immediately after it opened it. Any hints ? here's the code :
void ultraGrid1_ClickCellButton(object sender, CellEventArgs e) { Thread thread = new Thread(OpenMethod); thread.Name = "something"; thread.Start(); //thread.Join(); } private void OpenMethod() { if (_form == null) { _form = new NewForm(); _form.Closed += new EventHandler(_form_Closed); } _form.WindowState = FormWindowState.Normal; // bring it from the taskbar if necessary _form.Show(); }
Kind regards,Calling
Show
requires that the thread be running a message pump (like Application.Run). Replace_form.Show
with_form.ShowDialog
and it should work fine -ShowDialog
is modal and runs its own message pump.Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro