By default, threads you create are foreground threads.
Foreground threads keep the application alive for as long as any one of them is running.
Once all foreground threads finish, the application ends, and any background threads still running abruptly terminate.
You can query or change a thread's background status using its IsBackground prop- erty.
Here's an example:
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Thread worker = new Thread(() => Console.ReadLine());
if (args.Length > 0)
worker.IsBackground = true;
worker.Start();
}
}
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |