Reputation: 21406
If I call Application.Exit from my Winforms app in a form which has a running System.Windows.Forms.Timer, then will the timer also be stopped automatically?
public void StartProcessing()
{
int i = 0;
while (true)
{
if (BatchNumbersQueue.Count > 0)
{
i = BatchNumbersQueue[0];
}
else
{
//stop the time that queues batches and exit
timer1.Stop();
Application.Exit();
}
ProcessQueue();
QueueOfBatches.RemoveBatchToQueue(i);
i = 0;
}
}
//timer tick event
private void timer1_Tick(object sender, EventArgs e)
{
UpdateProcessingQueue();
}
Upvotes: 0
Views: 953
Reputation: 3855
I am quoting directly from MSDN here
The Exit method stops all running message loops on all threads and closes all windows of the application. This method does not necessarily force the application to exit. The Exit method is typically called from within a message loop, and forces Run to return.
To exit a message loop for the current thread only, call ExitThread.
Exit raises the following events and performs the associated conditional actions:
A FormClosing event is raised for every form represented by the OpenForms property. This event can be canceled by setting the Cancel property of their FormClosingEventArgs parameter to true. If one of more of the handlers cancels the event, then Exit returns without further action.
Otherwise, a FormClosed event is raised for every open form, then all running message loops and forms are closed.
In other words calling Exit()
will definitely stop and dispose of your Timer
object.
Upvotes: 2