Skip to content

Commit

Permalink
Ensure polling thread is joined when quitting
Browse files Browse the repository at this point in the history
  • Loading branch information
alk0ve committed Apr 16, 2022
1 parent 394546d commit c4887af
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion SerialPop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static class Program
// used to signal the end of the polling loop
static ManualResetEvent stopEvent = new ManualResetEvent(false);

static Thread pollingThread = null;

/*
* Prepare the text for the pop-up by comparing old and new port entries.
*/
Expand Down Expand Up @@ -209,6 +211,12 @@ private static void QuitButton_Click(object sender, EventArgs e)
// signal the polling thread to quit
stopEvent.Set();

// wait for thread to end
if (pollingThread != null)
{
pollingThread.Join();
}

// close the application in an orderly fashion
Application.Exit();
}
Expand Down Expand Up @@ -345,7 +353,8 @@ static void Main()
{
var applicationContext = new CustomApplicationContext();

Thread pollingThread = new Thread(new ParameterizedThreadStart(PollingLoop));
pollingThread = new Thread(new ParameterizedThreadStart(PollingLoop));
pollingThread.IsBackground = false;
pollingThread.Start(applicationContext.notifyIcon);

Application.Run(applicationContext);
Expand Down

0 comments on commit c4887af

Please sign in to comment.