Thread-ThreadStart
public sealed class Thread : CriticalFinalizerObject, _Thread {
[System.Security.SecuritySafeCritical] // auto-generated public Thread(ThreadStart start) { if (start == null) { throw new ArgumentNullException("start"); } Contract.EndContractBlock(); SetStartHelper((Delegate)start,0); //0 will setup Thread with default stackSize }
}
ThreadStart是一个无参无返回值的委托方法,实例化委托,也就是传递一个方法进去。
[System.Security.SecurityCritical] // auto-generated private void SetStartHelper(Delegate start, int maxStackSize) { #if FEATURE_CORECLR // We only support default stacks in CoreCLR Contract.Assert(maxStackSize == 0); #else // Only fully-trusted code is allowed to create "large" stacks. Partial-trust falls back to // the default stack size. ulong defaultStackSize = GetProcessDefaultStackSize(); if ((ulong)(uint)maxStackSize > defaultStackSize) { try { SecurityPermission.Demand(PermissionType.FullTrust); } catch (SecurityException) { maxStackSize = (int)Math.Min(defaultStackSize, (ulong)(uint)int.MaxValue); } } #endif ThreadHelper threadStartCallBack = new ThreadHelper(start); if(start is ThreadStart) { SetStart(new ThreadStart(threadStartCallBack.ThreadStart), maxStackSize); } else { SetStart(new ParameterizedThreadStart(threadStartCallBack.ThreadStart), maxStackSize); } }
namespace System.Threading { using System.Security.Permissions; using System.Threading; // Define the delegate // NOTE: If you change the signature here, there is code in COMSynchronization // that invokes this delegate in native. [System.Runtime.InteropServices.ComVisible(true)] public delegate void ThreadStart(); }