https://www.cnblogs.com/Sukie-s-home/p/6043779.html

【C#-多线程】实现每隔一段时间执行代码(多线程) 3种定时器

=====================
http://www.albahari.com/threading/
=====================
Thread myThread = new Thread(Go).Start();

线程优先级:
High is usually the best choice for real-time applications.
但是最高优先级的线程会让界面卡住

异常处理:
异步线程的异常要在异步线程当中处理,主线程无法捕获异步线程的exception

Thread Pooling
多线程的最佳方式,托管到线程池
There are a number of ways to enter the thread pool:

  • Via the Task Parallel Library (from Framework 4.0)
  • By calling [ThreadPool.QueueUserWorkItem](http://www.albahari.com/threading/#_QueueUserWorkItem)
  • Via asynchronous delegates
  • Via [BackgroundWorker](http://www.albahari.com/threading/part3.aspx#_BackgroundWorker)

The following constructs use the thread pool indirectly:

  • WCF, Remoting, ASP.NET, and ASMX Web Services application servers
  • [System.Timers.Timer](http://www.albahari.com/threading/part3.aspx#_Multithreaded_Timers)and [System.Threading.Timer](http://www.albahari.com/threading/part3.aspx#_Multithreaded_Timers)
  • Framework methods that end in Async, such as those on WebClient (the event-based asynchronous pattern), and most BeginXXX methods (the asynchronous programming model pattern)
  • PLINQ

线程锁

Simple blocking methods简单锁
These wait for another thread to finish or for a period of time to elapse. Sleep, Join, and Task.Waitare simple blocking methods.
Locking constructs锁构造
These limit the number of threads that can perform some activity or execute a section of code at a time. Exclusive locking constructs are most common — these allow just one thread in at a time, and allow competing threads to access common data without interfering with each other. The standard exclusive locking constructs are [lock](http://www.albahari.com/threading/part2.aspx#_Locking) (Monitor.Enter/Monitor.Exit), [Mutex](http://www.albahari.com/threading/part2.aspx#_Mutex), and SpinLock. The nonexclusive locking constructs are [Semaphore](http://www.albahari.com/threading/part2.aspx#_Semaphore), [SemaphoreSlim](http://www.albahari.com/threading/part2.aspx#_Semaphore), and the reader/writer locks.
Signaling constructs信号构造
These allow a thread to pause until receiving a notification from another, avoiding the need for inefficient polling. There are two commonly used signaling devices: event wait handles and Monitor’s [Wait/Pulse](http://www.albahari.com/threading/part4.aspx#_Signaling_with_Wait_and_Pulse) methods. Framework 4.0 introduces the [CountdownEvent](http://www.albahari.com/threading/part2.aspx#_CountdownEvent) and [Barrier](http://www.albahari.com/threading/part4.aspx#_The_Barrier_Class)classes.
Nonblocking synchronization constructs不闭塞同步构造
These protect access to a common field by calling upon processor primitives. The CLR and C# provide the following nonblocking constructs: [Thread.MemoryBarrier, Thread.VolatileRead, Thread.VolatileWrite](http://www.albahari.com/threading/part4.aspx#_Memory_Barriers_and_Volatility), the [volatile](http://www.albahari.com/threading/part4.aspx#_The_volatile_keyword) keyword, and the [Interlocked](http://www.albahari.com/threading/part4.aspx#_Interlocked) class.
Blocking is essential to all but the last category. Let’s briefly examine this concept.

static readonly object _locker = new object();