A
Andrew
I have a multi-threaded console application running in Windows CE using the
..NET Compact Framework 2.0.
The following code exits the program and correctly terminates the threads
created.
static void Main(string[] args)
{
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
//
// create metar serial port instance
metarCom = new SerialPort();
metarCom.ReadTimeout = 500;
//
// create task scheduler instance
taskScheduler = new ScheduledTimer();
taskScheduler.SchedulerElapsed += new
SchedulerElapsedEventHandler(taskScheduler_SchedulerElapsed);
//
// create settings instance
settings = new ManagerSettings(AppPath + "\\AgentSettings.xml");
//
// initialize settings
InitializeSettings();
//
// open metar serial port
if(metarEnabled)
metarCom.Open();
//
// create thread instance to read
// serial port
readThread = new Thread(Read);
read = true;
if(metarEnabled)
readThread.Start();
//
//
// start scheduler
taskScheduler.Start();
//
Console.WriteLine("Type QUIT to exit");
//
// loop until quit message entered
while (read)
{
// read input message
message = Console.ReadLine();
//
// quit console application
if (stringComparer.Equals("quit", message))
read = false;
//
// sleep for 10ms - frees resources
Thread.Sleep(10);
}
//
// kill the read thread
if (readThread != null)
readThread.Join();
readThread = null;
//
// destroy metar com object instance
if (metarCom != null)
{
metarCom.Dispose();
metarCom.Close();
}
metarCom = null;
}
However, if I kill the process from an external program, or close the CMD
instance that it it running in, it leaves part of the application running.
My question is - How do I test for these other methods of quitting the
application?
Thanks
..NET Compact Framework 2.0.
The following code exits the program and correctly terminates the threads
created.
static void Main(string[] args)
{
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
//
// create metar serial port instance
metarCom = new SerialPort();
metarCom.ReadTimeout = 500;
//
// create task scheduler instance
taskScheduler = new ScheduledTimer();
taskScheduler.SchedulerElapsed += new
SchedulerElapsedEventHandler(taskScheduler_SchedulerElapsed);
//
// create settings instance
settings = new ManagerSettings(AppPath + "\\AgentSettings.xml");
//
// initialize settings
InitializeSettings();
//
// open metar serial port
if(metarEnabled)
metarCom.Open();
//
// create thread instance to read
// serial port
readThread = new Thread(Read);
read = true;
if(metarEnabled)
readThread.Start();
//
//
// start scheduler
taskScheduler.Start();
//
Console.WriteLine("Type QUIT to exit");
//
// loop until quit message entered
while (read)
{
// read input message
message = Console.ReadLine();
//
// quit console application
if (stringComparer.Equals("quit", message))
read = false;
//
// sleep for 10ms - frees resources
Thread.Sleep(10);
}
//
// kill the read thread
if (readThread != null)
readThread.Join();
readThread = null;
//
// destroy metar com object instance
if (metarCom != null)
{
metarCom.Dispose();
metarCom.Close();
}
metarCom = null;
}
However, if I kill the process from an external program, or close the CMD
instance that it it running in, it leaves part of the application running.
My question is - How do I test for these other methods of quitting the
application?
Thanks