avoid an application closing when calculations are in progress?
-
Hello gurus, I'd like to know how to avoid an application closing when calculations are being performed? I tried to trap the
Closing
event and set thee.Cancel
tofalse
, but it quits anyway :(private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_permuting) e.Cancel=!_permuting; }
Thanks for the help. There is no spoon. -
Hello gurus, I'd like to know how to avoid an application closing when calculations are being performed? I tried to trap the
Closing
event and set thee.Cancel
tofalse
, but it quits anyway :(private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_permuting) e.Cancel=!_permuting; }
Thanks for the help. There is no spoon. -
Hello gurus, I'd like to know how to avoid an application closing when calculations are being performed? I tried to trap the
Closing
event and set thee.Cancel
tofalse
, but it quits anyway :(private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_permuting) e.Cancel=!_permuting; }
Thanks for the help. There is no spoon.This is a multithreading issue. 1.Spawn a worker thread with the the long calculation
Thread m_Thread;
...
m_Thread = new Thread(new ThreadStart(MyLongCalculationFunction));
m_Thread.Start();2.In your Form_Closing handler check the thread state
if (m_Thread.ThreadState == ThreadState.Running) ...
If running, dont let the dialog close by giving
e.Cancel = true;
Peter Molnar