J
Juha Nieminen
I have created an application using Visual Studio 2008 Express, in
C++.NET, using the gui designer.
The app consists of one single form, and what it does is that the GUI
can be used to set up options and parameters as well as the input data,
and then a "run" button can be clicked. This launches a thread which
performs heavy-duty calculations on that data (which may take minutes or
more). The GUI thread uses a timer to update itself (show progress,
etc). In this mode it also has a "stop" button which tells the
calculation thread to stop immediately.
This all works just fine. There's one big problem, though: If I close
the app without stopping the calculations, the calculations thread will
not stop until it's done. This means that although the app window has
been closed, the app itself will be running in the background for as
long as it takes for the calculations, and the only way to stop it is to
kill it from the process manager.
The solution would seem to be simple: When closing the app is
requested, make it stop the calculations thread. However, I have no idea
how this can be done. The form has a "is going to close" event trigger
which sounds like could work, but it doesn't: That function doesn't get
called until the calculation thread ends, even if the app window is
closed. There's also a "was closed" event, but it doesn't work either.
How to properly catch that the user is closing the app, so that I can
make the calculation thread stop at that point immediately?
C++.NET, using the gui designer.
The app consists of one single form, and what it does is that the GUI
can be used to set up options and parameters as well as the input data,
and then a "run" button can be clicked. This launches a thread which
performs heavy-duty calculations on that data (which may take minutes or
more). The GUI thread uses a timer to update itself (show progress,
etc). In this mode it also has a "stop" button which tells the
calculation thread to stop immediately.
This all works just fine. There's one big problem, though: If I close
the app without stopping the calculations, the calculations thread will
not stop until it's done. This means that although the app window has
been closed, the app itself will be running in the background for as
long as it takes for the calculations, and the only way to stop it is to
kill it from the process manager.
The solution would seem to be simple: When closing the app is
requested, make it stop the calculations thread. However, I have no idea
how this can be done. The form has a "is going to close" event trigger
which sounds like could work, but it doesn't: That function doesn't get
called until the calculation thread ends, even if the app window is
closed. There's also a "was closed" event, but it doesn't work either.
How to properly catch that the user is closing the app, so that I can
make the calculation thread stop at that point immediately?