mscorlib(4.0.0.0) API with additions
Thread.cs
7 using System.Security;
10 
11 namespace System.Threading
12 {
14  [ClassInterface(ClassInterfaceType.None)]
15  [ComDefaultInterface(typeof(_Thread))]
16  [ComVisible(true)]
17  [__DynamicallyInvokable]
18  public sealed class Thread : CriticalFinalizerObject, _Thread
19  {
20  private Context m_Context;
21 
22  private ExecutionContext m_ExecutionContext;
23 
24  private string m_Name;
25 
26  private Delegate m_Delegate;
27 
28  private CultureInfo m_CurrentCulture;
29 
30  private CultureInfo m_CurrentUICulture;
31 
32  private object m_ThreadStartArg;
33 
34  private IntPtr DONT_USE_InternalThread;
35 
36  private int m_Priority;
37 
38  private int m_ManagedThreadId;
39 
40  private bool m_ExecutionContextBelongsToOuterScope;
41 
42  private static LocalDataStoreMgr s_LocalDataStoreMgr;
43 
44  [ThreadStatic]
45  private static LocalDataStoreHolder s_LocalDataStore;
46 
47  private static AsyncLocal<CultureInfo> s_asyncLocalCurrentCulture;
48 
49  private static AsyncLocal<CultureInfo> s_asyncLocalCurrentUICulture;
50 
53  [__DynamicallyInvokable]
54  public int ManagedThreadId
55  {
56  [MethodImpl(MethodImplOptions.InternalCall)]
57  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
58  [SecuritySafeCritical]
59  [__DynamicallyInvokable]
60  get;
61  }
62 
63  internal bool ExecutionContextBelongsToCurrentScope
64  {
65  get
66  {
67  return !m_ExecutionContextBelongsToOuterScope;
68  }
69  set
70  {
71  m_ExecutionContextBelongsToOuterScope = !value;
72  }
73  }
74 
78  {
79  [SecuritySafeCritical]
80  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
81  get
82  {
83  if (this == CurrentThread)
84  {
85  return GetMutableExecutionContext();
86  }
87  return m_ExecutionContext;
88  }
89  }
90 
96  {
97  [SecuritySafeCritical]
98  get
99  {
100  return (ThreadPriority)GetPriorityNative();
101  }
102  [SecuritySafeCritical]
103  [HostProtection(SecurityAction.LinkDemand, SelfAffectingThreading = true)]
104  set
105  {
106  SetPriorityNative((int)value);
107  }
108  }
109 
113  public bool IsAlive
114  {
115  [MethodImpl(MethodImplOptions.InternalCall)]
116  [SecuritySafeCritical]
117  get;
118  }
119 
123  public bool IsThreadPoolThread
124  {
125  [MethodImpl(MethodImplOptions.InternalCall)]
126  [SecuritySafeCritical]
127  get;
128  }
129 
132  [__DynamicallyInvokable]
133  public static Thread CurrentThread
134  {
135  [SecuritySafeCritical]
136  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
137  [__DynamicallyInvokable]
138  get
139  {
140  return GetCurrentThreadNative();
141  }
142  }
143 
148  public bool IsBackground
149  {
150  [SecuritySafeCritical]
151  get
152  {
153  return IsBackgroundNative();
154  }
155  [SecuritySafeCritical]
156  [HostProtection(SecurityAction.LinkDemand, SelfAffectingThreading = true)]
157  set
158  {
159  SetBackgroundNative(value);
160  }
161  }
162 
165  public ThreadState ThreadState
166  {
167  [SecuritySafeCritical]
168  get
169  {
170  return (ThreadState)GetThreadStateNative();
171  }
172  }
173 
177  [Obsolete("The ApartmentState property has been deprecated. Use GetApartmentState, SetApartmentState or TrySetApartmentState instead.", false)]
179  {
180  [SecuritySafeCritical]
181  get
182  {
183  return (ApartmentState)GetApartmentStateNative();
184  }
185  [SecuritySafeCritical]
186  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, SelfAffectingThreading = true)]
187  set
188  {
189  SetApartmentStateNative((int)value, fireMDAOnMismatch: true);
190  }
191  }
192 
197  [__DynamicallyInvokable]
199  {
200  [__DynamicallyInvokable]
201  get
202  {
203  if (AppDomain.IsAppXModel())
204  {
205  return CultureInfo.GetCultureInfoForUserPreferredLanguageInAppX() ?? GetCurrentUICultureNoAppX();
206  }
207  return GetCurrentUICultureNoAppX();
208  }
209  [SecuritySafeCritical]
210  [__DynamicallyInvokable]
211  [HostProtection(SecurityAction.LinkDemand, ExternalThreading = true)]
212  set
213  {
214  if (value == null)
215  {
216  throw new ArgumentNullException("value");
217  }
218  CultureInfo.VerifyCultureName(value, throwException: true);
219  if (!nativeSetThreadUILocale(value.SortName))
220  {
221  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidResourceCultureName", value.Name));
222  }
223  value.StartCrossDomainTracking();
224  if (!AppContextSwitches.NoAsyncCurrentCulture)
225  {
226  if (s_asyncLocalCurrentUICulture == null)
227  {
228  Interlocked.CompareExchange(ref s_asyncLocalCurrentUICulture, new AsyncLocal<CultureInfo>(AsyncLocalSetCurrentUICulture), null);
229  }
230  s_asyncLocalCurrentUICulture.Value = value;
231  }
232  else
233  {
234  m_CurrentUICulture = value;
235  }
236  }
237  }
238 
243  [__DynamicallyInvokable]
245  {
246  [__DynamicallyInvokable]
247  get
248  {
249  if (AppDomain.IsAppXModel())
250  {
251  return CultureInfo.GetCultureInfoForUserPreferredLanguageInAppX() ?? GetCurrentCultureNoAppX();
252  }
253  return GetCurrentCultureNoAppX();
254  }
255  [SecuritySafeCritical]
256  [__DynamicallyInvokable]
258  set
259  {
260  if (value == null)
261  {
262  throw new ArgumentNullException("value");
263  }
264  CultureInfo.nativeSetThreadLocale(value.SortName);
265  value.StartCrossDomainTracking();
266  if (!AppContextSwitches.NoAsyncCurrentCulture)
267  {
268  if (s_asyncLocalCurrentCulture == null)
269  {
270  Interlocked.CompareExchange(ref s_asyncLocalCurrentCulture, new AsyncLocal<CultureInfo>(AsyncLocalSetCurrentCulture), null);
271  }
272  s_asyncLocalCurrentCulture.Value = value;
273  }
274  else
275  {
276  m_CurrentCulture = value;
277  }
278  }
279  }
280 
284  public static Context CurrentContext
285  {
286  [SecurityCritical]
287  get
288  {
289  return CurrentThread.GetCurrentContextInternal();
290  }
291  }
292 
296  public static IPrincipal CurrentPrincipal
297  {
298  [SecuritySafeCritical]
299  get
300  {
301  lock (CurrentThread)
302  {
303  IPrincipal principal = CallContext.Principal;
304  if (principal == null)
305  {
306  principal = (CallContext.Principal = GetDomain().GetThreadPrincipal());
307  }
308  return principal;
309  }
310  }
311  [SecuritySafeCritical]
312  [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlPrincipal)]
313  set
314  {
315  CallContext.Principal = value;
316  }
317  }
318 
322  public string Name
323  {
324  get
325  {
326  return m_Name;
327  }
328  [SecuritySafeCritical]
329  [HostProtection(SecurityAction.LinkDemand, ExternalThreading = true)]
330  set
331  {
332  lock (this)
333  {
334  if (m_Name != null)
335  {
336  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_WriteOnce"));
337  }
338  m_Name = value;
339  InformThreadNameChange(GetNativeHandle(), value, value?.Length ?? 0);
340  }
341  }
342  }
343 
344  internal object AbortReason
345  {
346  [SecurityCritical]
347  get
348  {
349  object obj = null;
350  try
351  {
352  return GetAbortReason();
353  }
354  catch (Exception innerException)
355  {
356  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ExceptionStateCrossAppDomain"), innerException);
357  }
358  }
359  [SecurityCritical]
360  set
361  {
362  SetAbortReason(value);
363  }
364  }
365 
366  private static LocalDataStoreMgr LocalDataStoreManager
367  {
368  get
369  {
370  if (s_LocalDataStoreMgr == null)
371  {
372  Interlocked.CompareExchange(ref s_LocalDataStoreMgr, new LocalDataStoreMgr(), null);
373  }
374  return s_LocalDataStoreMgr;
375  }
376  }
377 
378  private static void AsyncLocalSetCurrentCulture(AsyncLocalValueChangedArgs<CultureInfo> args)
379  {
380  CurrentThread.m_CurrentCulture = args.CurrentValue;
381  }
382 
383  private static void AsyncLocalSetCurrentUICulture(AsyncLocalValueChangedArgs<CultureInfo> args)
384  {
385  CurrentThread.m_CurrentUICulture = args.CurrentValue;
386  }
387 
391  [SecuritySafeCritical]
392  public Thread(ThreadStart start)
393  {
394  if (start == null)
395  {
396  throw new ArgumentNullException("start");
397  }
398  SetStartHelper(start, 0);
399  }
400 
408  [SecuritySafeCritical]
409  public Thread(ThreadStart start, int maxStackSize)
410  {
411  if (start == null)
412  {
413  throw new ArgumentNullException("start");
414  }
415  if (0 > maxStackSize)
416  {
417  throw new ArgumentOutOfRangeException("maxStackSize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
418  }
419  SetStartHelper(start, maxStackSize);
420  }
421 
426  [SecuritySafeCritical]
428  {
429  if (start == null)
430  {
431  throw new ArgumentNullException("start");
432  }
433  SetStartHelper(start, 0);
434  }
435 
443  [SecuritySafeCritical]
444  public Thread(ParameterizedThreadStart start, int maxStackSize)
445  {
446  if (start == null)
447  {
448  throw new ArgumentNullException("start");
449  }
450  if (0 > maxStackSize)
451  {
452  throw new ArgumentOutOfRangeException("maxStackSize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
453  }
454  SetStartHelper(start, maxStackSize);
455  }
456 
459  [ComVisible(false)]
460  public override int GetHashCode()
461  {
462  return m_ManagedThreadId;
463  }
464 
465  internal ThreadHandle GetNativeHandle()
466  {
467  IntPtr dONT_USE_InternalThread = DONT_USE_InternalThread;
468  if (dONT_USE_InternalThread.IsNull())
469  {
470  throw new ArgumentException(null, Environment.GetResourceString("Argument_InvalidHandle"));
471  }
472  return new ThreadHandle(dONT_USE_InternalThread);
473  }
474 
478  [MethodImpl(MethodImplOptions.NoInlining)]
479  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
480  public void Start()
481  {
482  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
483  Start(ref stackMark);
484  }
485 
491  [MethodImpl(MethodImplOptions.NoInlining)]
492  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
493  public void Start(object parameter)
494  {
495  if (m_Delegate is ThreadStart)
496  {
497  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ThreadWrongThreadStart"));
498  }
499  m_ThreadStartArg = parameter;
500  StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
501  Start(ref stackMark);
502  }
503 
504  [SecuritySafeCritical]
505  private void Start(ref StackCrawlMark stackMark)
506  {
507  StartupSetApartmentStateInternal();
508  if ((object)m_Delegate != null)
509  {
510  ThreadHelper threadHelper = (ThreadHelper)m_Delegate.Target;
511  ExecutionContext executionContextHelper = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx);
512  threadHelper.SetExecutionContextHelper(executionContextHelper);
513  }
514  IPrincipal principal = CallContext.Principal;
515  StartInternal(principal, ref stackMark);
516  }
517 
518  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
519  internal ExecutionContext.Reader GetExecutionContextReader()
520  {
521  return new ExecutionContext.Reader(m_ExecutionContext);
522  }
523 
524  [SecurityCritical]
525  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
526  internal ExecutionContext GetMutableExecutionContext()
527  {
528  if (m_ExecutionContext == null)
529  {
530  m_ExecutionContext = new ExecutionContext();
531  }
532  else if (!ExecutionContextBelongsToCurrentScope)
533  {
534  ExecutionContext executionContext = m_ExecutionContext = m_ExecutionContext.CreateMutableCopy();
535  }
536  ExecutionContextBelongsToCurrentScope = true;
537  return m_ExecutionContext;
538  }
539 
540  [SecurityCritical]
541  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
542  internal void SetExecutionContext(ExecutionContext value, bool belongsToCurrentScope)
543  {
544  m_ExecutionContext = value;
545  ExecutionContextBelongsToCurrentScope = belongsToCurrentScope;
546  }
547 
548  [SecurityCritical]
549  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
550  internal void SetExecutionContext(ExecutionContext.Reader value, bool belongsToCurrentScope)
551  {
552  m_ExecutionContext = value.DangerousGetRawExecutionContext();
553  ExecutionContextBelongsToCurrentScope = belongsToCurrentScope;
554  }
555 
556  [MethodImpl(MethodImplOptions.InternalCall)]
557  [SecurityCritical]
558  private extern void StartInternal(IPrincipal principal, ref StackCrawlMark stackMark);
559 
563  [SecurityCritical]
564  [Obsolete("Thread.SetCompressedStack is no longer supported. Please use the System.Threading.CompressedStack class")]
566  {
567  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ThreadAPIsNotSupported"));
568  }
569 
570  [MethodImpl(MethodImplOptions.InternalCall)]
571  [SecurityCritical]
572  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
573  internal extern IntPtr SetAppDomainStack(SafeCompressedStackHandle csHandle);
574 
575  [MethodImpl(MethodImplOptions.InternalCall)]
576  [SecurityCritical]
577  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
578  internal extern void RestoreAppDomainStack(IntPtr appDomainStack);
579 
584  [SecurityCritical]
585  [Obsolete("Thread.GetCompressedStack is no longer supported. Please use the System.Threading.CompressedStack class")]
587  {
588  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ThreadAPIsNotSupported"));
589  }
590 
591  [MethodImpl(MethodImplOptions.InternalCall)]
592  [SecurityCritical]
593  internal static extern IntPtr InternalGetCurrentThread();
594 
599  [SecuritySafeCritical]
600  [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
601  public void Abort(object stateInfo)
602  {
603  AbortReason = stateInfo;
604  AbortInternal();
605  }
606 
610  [SecuritySafeCritical]
611  [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
612  public void Abort()
613  {
614  AbortInternal();
615  }
616 
617  [MethodImpl(MethodImplOptions.InternalCall)]
618  [SecurityCritical]
619  private extern void AbortInternal();
620 
625  [SecuritySafeCritical]
626  [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
627  public static void ResetAbort()
628  {
629  Thread currentThread = CurrentThread;
630  if ((currentThread.ThreadState & ThreadState.AbortRequested) == ThreadState.Running)
631  {
632  throw new ThreadStateException(Environment.GetResourceString("ThreadState_NoAbortRequested"));
633  }
634  currentThread.ResetAbortNative();
635  currentThread.ClearAbortReason();
636  }
637 
638  [MethodImpl(MethodImplOptions.InternalCall)]
639  [SecurityCritical]
640  private extern void ResetAbortNative();
641 
645  [SecuritySafeCritical]
646  [Obsolete("Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. http://go.microsoft.com/fwlink/?linkid=14202", false)]
647  [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
648  [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
649  public void Suspend()
650  {
651  SuspendInternal();
652  }
653 
654  [MethodImpl(MethodImplOptions.InternalCall)]
655  [SecurityCritical]
656  private extern void SuspendInternal();
657 
661  [SecuritySafeCritical]
662  [Obsolete("Thread.Resume has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. http://go.microsoft.com/fwlink/?linkid=14202", false)]
663  [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
664  public void Resume()
665  {
666  ResumeInternal();
667  }
668 
669  [MethodImpl(MethodImplOptions.InternalCall)]
670  [SecurityCritical]
671  private extern void ResumeInternal();
672 
675  [SecuritySafeCritical]
676  [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
677  public void Interrupt()
678  {
679  InterruptInternal();
680  }
681 
682  [MethodImpl(MethodImplOptions.InternalCall)]
683  [SecurityCritical]
684  private extern void InterruptInternal();
685 
686  [MethodImpl(MethodImplOptions.InternalCall)]
687  [SecurityCritical]
688  private extern int GetPriorityNative();
689 
690  [MethodImpl(MethodImplOptions.InternalCall)]
691  [SecurityCritical]
692  private extern void SetPriorityNative(int priority);
693 
694  [MethodImpl(MethodImplOptions.InternalCall)]
695  [SecurityCritical]
696  private extern bool JoinInternal(int millisecondsTimeout);
697 
701  [SecuritySafeCritical]
702  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
703  public void Join()
704  {
705  JoinInternal(-1);
706  }
707 
714  [SecuritySafeCritical]
715  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
716  public bool Join(int millisecondsTimeout)
717  {
718  return JoinInternal(millisecondsTimeout);
719  }
720 
727  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
728  public bool Join(TimeSpan timeout)
729  {
730  long num = (long)timeout.TotalMilliseconds;
731  if (num < -1 || num > int.MaxValue)
732  {
733  throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
734  }
735  return Join((int)num);
736  }
737 
738  [MethodImpl(MethodImplOptions.InternalCall)]
739  [SecurityCritical]
740  private static extern void SleepInternal(int millisecondsTimeout);
741 
745  [SecuritySafeCritical]
746  public static void Sleep(int millisecondsTimeout)
747  {
748  SleepInternal(millisecondsTimeout);
749  if (AppDomainPauseManager.IsPaused)
750  {
751  AppDomainPauseManager.ResumeEvent.WaitOneWithoutFAS();
752  }
753  }
754 
758  public static void Sleep(TimeSpan timeout)
759  {
760  long num = (long)timeout.TotalMilliseconds;
761  if (num < -1 || num > int.MaxValue)
762  {
763  throw new ArgumentOutOfRangeException("timeout", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegOrNegative1"));
764  }
765  Sleep((int)num);
766  }
767 
768  [MethodImpl(MethodImplOptions.InternalCall)]
769  [SecurityCritical]
770  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
771  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
772  private static extern void SpinWaitInternal(int iterations);
773 
776  [SecuritySafeCritical]
777  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
778  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
779  public static void SpinWait(int iterations)
780  {
781  SpinWaitInternal(iterations);
782  }
783 
784  [DllImport("QCall", CharSet = CharSet.Unicode)]
785  [SecurityCritical]
786  [SuppressUnmanagedCodeSecurity]
787  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
788  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
789  private static extern bool YieldInternal();
790 
794  [SecuritySafeCritical]
795  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
796  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
797  public static bool Yield()
798  {
799  return YieldInternal();
800  }
801 
802  [MethodImpl(MethodImplOptions.InternalCall)]
803  [SecurityCritical]
804  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
805  private static extern Thread GetCurrentThreadNative();
806 
807  [SecurityCritical]
808  private void SetStartHelper(Delegate start, int maxStackSize)
809  {
810  ulong processDefaultStackSize = GetProcessDefaultStackSize();
811  if ((uint)maxStackSize > processDefaultStackSize)
812  {
813  try
814  {
815  CodeAccessPermission.Demand(PermissionType.FullTrust);
816  }
817  catch (SecurityException)
818  {
819  maxStackSize = (int)Math.Min(processDefaultStackSize, 2147483647uL);
820  }
821  }
822  ThreadHelper @object = new ThreadHelper(start);
823  if (start is ThreadStart)
824  {
825  SetStart(new ThreadStart(@object.ThreadStart), maxStackSize);
826  }
827  else
828  {
829  SetStart(new ParameterizedThreadStart(@object.ThreadStart), maxStackSize);
830  }
831  }
832 
833  [DllImport("QCall", CharSet = CharSet.Unicode)]
834  [SecurityCritical]
835  [SuppressUnmanagedCodeSecurity]
836  private static extern ulong GetProcessDefaultStackSize();
837 
838  [MethodImpl(MethodImplOptions.InternalCall)]
839  [SecurityCritical]
840  private extern void SetStart(Delegate start, int maxStackSize);
841 
843  [SecuritySafeCritical]
844  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
845  ~Thread()
846  {
847  InternalFinalize();
848  }
849 
850  [MethodImpl(MethodImplOptions.InternalCall)]
851  [SecurityCritical]
852  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
853  private extern void InternalFinalize();
854 
856  [MethodImpl(MethodImplOptions.InternalCall)]
857  [SecurityCritical]
858  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
859  public extern void DisableComObjectEagerCleanup();
860 
861  [MethodImpl(MethodImplOptions.InternalCall)]
862  [SecurityCritical]
863  private extern bool IsBackgroundNative();
864 
865  [MethodImpl(MethodImplOptions.InternalCall)]
866  [SecurityCritical]
867  private extern void SetBackgroundNative(bool isBackground);
868 
869  [MethodImpl(MethodImplOptions.InternalCall)]
870  [SecurityCritical]
871  private extern int GetThreadStateNative();
872 
875  [SecuritySafeCritical]
877  {
878  return (ApartmentState)GetApartmentStateNative();
879  }
880 
888  [SecuritySafeCritical]
889  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, SelfAffectingThreading = true)]
891  {
892  return SetApartmentStateHelper(state, fireMDAOnMismatch: false);
893  }
894 
901  [SecuritySafeCritical]
902  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, SelfAffectingThreading = true)]
904  {
905  if (!SetApartmentStateHelper(state, fireMDAOnMismatch: true))
906  {
907  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ApartmentStateSwitchFailed"));
908  }
909  }
910 
911  [SecurityCritical]
912  private bool SetApartmentStateHelper(ApartmentState state, bool fireMDAOnMismatch)
913  {
914  ApartmentState apartmentState = (ApartmentState)SetApartmentStateNative((int)state, fireMDAOnMismatch);
915  if (state == ApartmentState.Unknown && apartmentState == ApartmentState.MTA)
916  {
917  return true;
918  }
919  if (apartmentState != state)
920  {
921  return false;
922  }
923  return true;
924  }
925 
926  [MethodImpl(MethodImplOptions.InternalCall)]
927  [SecurityCritical]
928  private extern int GetApartmentStateNative();
929 
930  [MethodImpl(MethodImplOptions.InternalCall)]
931  [SecurityCritical]
932  private extern int SetApartmentStateNative(int state, bool fireMDAOnMismatch);
933 
934  [MethodImpl(MethodImplOptions.InternalCall)]
935  [SecurityCritical]
936  private extern void StartupSetApartmentStateInternal();
937 
940  [HostProtection(SecurityAction.LinkDemand, SharedState = true, ExternalThreading = true)]
942  {
943  return LocalDataStoreManager.AllocateDataSlot();
944  }
945 
950  [HostProtection(SecurityAction.LinkDemand, SharedState = true, ExternalThreading = true)]
951  public static LocalDataStoreSlot AllocateNamedDataSlot(string name)
952  {
953  return LocalDataStoreManager.AllocateNamedDataSlot(name);
954  }
955 
959  [HostProtection(SecurityAction.LinkDemand, SharedState = true, ExternalThreading = true)]
960  public static LocalDataStoreSlot GetNamedDataSlot(string name)
961  {
962  return LocalDataStoreManager.GetNamedDataSlot(name);
963  }
964 
967  [HostProtection(SecurityAction.LinkDemand, SharedState = true, ExternalThreading = true)]
968  public static void FreeNamedDataSlot(string name)
969  {
970  LocalDataStoreManager.FreeNamedDataSlot(name);
971  }
972 
976  [HostProtection(SecurityAction.LinkDemand, SharedState = true, ExternalThreading = true)]
977  public static object GetData(LocalDataStoreSlot slot)
978  {
979  LocalDataStoreHolder localDataStoreHolder = s_LocalDataStore;
980  if (localDataStoreHolder == null)
981  {
982  LocalDataStoreManager.ValidateSlot(slot);
983  return null;
984  }
985  return localDataStoreHolder.Store.GetData(slot);
986  }
987 
991  [HostProtection(SecurityAction.LinkDemand, SharedState = true, ExternalThreading = true)]
992  public static void SetData(LocalDataStoreSlot slot, object data)
993  {
994  LocalDataStoreHolder localDataStoreHolder = s_LocalDataStore;
995  if (localDataStoreHolder == null)
996  {
997  localDataStoreHolder = (s_LocalDataStore = LocalDataStoreManager.CreateLocalDataStore());
998  }
999  localDataStoreHolder.Store.SetData(slot, data);
1000  }
1001 
1002  [MethodImpl(MethodImplOptions.InternalCall)]
1003  [SecurityCritical]
1004  private static extern bool nativeGetSafeCulture(Thread t, int appDomainId, bool isUI, ref CultureInfo safeCulture);
1005 
1006  [SecuritySafeCritical]
1007  internal CultureInfo GetCurrentUICultureNoAppX()
1008  {
1009  if (m_CurrentUICulture == null)
1010  {
1011  CultureInfo defaultThreadCurrentUICulture = CultureInfo.DefaultThreadCurrentUICulture;
1012  if (defaultThreadCurrentUICulture == null)
1013  {
1014  return CultureInfo.UserDefaultUICulture;
1015  }
1016  return defaultThreadCurrentUICulture;
1017  }
1018  CultureInfo safeCulture = null;
1019  if (!nativeGetSafeCulture(this, GetDomainID(), isUI: true, ref safeCulture) || safeCulture == null)
1020  {
1021  return CultureInfo.UserDefaultUICulture;
1022  }
1023  return safeCulture;
1024  }
1025 
1026  [MethodImpl(MethodImplOptions.InternalCall)]
1027  [SecurityCritical]
1028  private static extern bool nativeSetThreadUILocale(string locale);
1029 
1030  [SecuritySafeCritical]
1031  private CultureInfo GetCurrentCultureNoAppX()
1032  {
1033  if (m_CurrentCulture == null)
1034  {
1035  CultureInfo defaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentCulture;
1036  if (defaultThreadCurrentCulture == null)
1037  {
1038  return CultureInfo.UserDefaultCulture;
1039  }
1040  return defaultThreadCurrentCulture;
1041  }
1042  CultureInfo safeCulture = null;
1043  if (!nativeGetSafeCulture(this, GetDomainID(), isUI: false, ref safeCulture) || safeCulture == null)
1044  {
1045  return CultureInfo.UserDefaultCulture;
1046  }
1047  return safeCulture;
1048  }
1049 
1050  [SecurityCritical]
1051  internal Context GetCurrentContextInternal()
1052  {
1053  if (m_Context == null)
1054  {
1055  m_Context = Context.DefaultContext;
1056  }
1057  return m_Context;
1058  }
1059 
1060  [SecurityCritical]
1061  private void SetPrincipalInternal(IPrincipal principal)
1062  {
1063  GetMutableExecutionContext().LogicalCallContext.SecurityData.Principal = principal;
1064  }
1065 
1066  [MethodImpl(MethodImplOptions.InternalCall)]
1067  [SecurityCritical]
1068  internal static extern Context GetContextInternal(IntPtr id);
1069 
1070  [MethodImpl(MethodImplOptions.InternalCall)]
1071  [SecurityCritical]
1072  internal extern object InternalCrossContextCallback(Context ctx, IntPtr ctxID, int appDomainID, InternalCrossContextDelegate ftnToCall, object[] args);
1073 
1074  [SecurityCritical]
1075  internal object InternalCrossContextCallback(Context ctx, InternalCrossContextDelegate ftnToCall, object[] args)
1076  {
1077  return InternalCrossContextCallback(ctx, ctx.InternalContextID, 0, ftnToCall, args);
1078  }
1079 
1080  private static object CompleteCrossContextCallback(InternalCrossContextDelegate ftnToCall, object[] args)
1081  {
1082  return ftnToCall(args);
1083  }
1084 
1085  [MethodImpl(MethodImplOptions.InternalCall)]
1086  [SecurityCritical]
1087  private static extern AppDomain GetDomainInternal();
1088 
1089  [MethodImpl(MethodImplOptions.InternalCall)]
1090  [SecurityCritical]
1091  private static extern AppDomain GetFastDomainInternal();
1092 
1095  [SecuritySafeCritical]
1096  public static AppDomain GetDomain()
1097  {
1098  AppDomain appDomain = GetFastDomainInternal();
1099  if (appDomain == null)
1100  {
1101  appDomain = GetDomainInternal();
1102  }
1103  return appDomain;
1104  }
1105 
1108  public static int GetDomainID()
1109  {
1110  return GetDomain().GetId();
1111  }
1112 
1113  [DllImport("QCall", CharSet = CharSet.Unicode)]
1114  [SecurityCritical]
1115  [SuppressUnmanagedCodeSecurity]
1116  private static extern void InformThreadNameChange(ThreadHandle t, string name, int len);
1117 
1119  [MethodImpl(MethodImplOptions.InternalCall)]
1120  [SecuritySafeCritical]
1121  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
1122  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
1123  public static extern void BeginCriticalRegion();
1124 
1126  [MethodImpl(MethodImplOptions.InternalCall)]
1127  [SecuritySafeCritical]
1128  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
1129  [HostProtection(SecurityAction.LinkDemand, Synchronization = true, ExternalThreading = true)]
1130  public static extern void EndCriticalRegion();
1131 
1134  [MethodImpl(MethodImplOptions.InternalCall)]
1135  [SecurityCritical]
1136  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
1137  public static extern void BeginThreadAffinity();
1138 
1141  [MethodImpl(MethodImplOptions.InternalCall)]
1142  [SecurityCritical]
1143  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
1144  public static extern void EndThreadAffinity();
1145 
1149  [MethodImpl(MethodImplOptions.NoInlining)]
1150  public static byte VolatileRead(ref byte address)
1151  {
1152  byte result = address;
1153  MemoryBarrier();
1154  return result;
1155  }
1156 
1160  [MethodImpl(MethodImplOptions.NoInlining)]
1161  public static short VolatileRead(ref short address)
1162  {
1163  short result = address;
1164  MemoryBarrier();
1165  return result;
1166  }
1167 
1171  [MethodImpl(MethodImplOptions.NoInlining)]
1172  public static int VolatileRead(ref int address)
1173  {
1174  int result = address;
1175  MemoryBarrier();
1176  return result;
1177  }
1178 
1182  [MethodImpl(MethodImplOptions.NoInlining)]
1183  public static long VolatileRead(ref long address)
1184  {
1185  long result = address;
1186  MemoryBarrier();
1187  return result;
1188  }
1189 
1193  [MethodImpl(MethodImplOptions.NoInlining)]
1194  [CLSCompliant(false)]
1195  public static sbyte VolatileRead(ref sbyte address)
1196  {
1197  sbyte result = address;
1198  MemoryBarrier();
1199  return result;
1200  }
1201 
1205  [MethodImpl(MethodImplOptions.NoInlining)]
1206  [CLSCompliant(false)]
1207  public static ushort VolatileRead(ref ushort address)
1208  {
1209  ushort result = address;
1210  MemoryBarrier();
1211  return result;
1212  }
1213 
1217  [MethodImpl(MethodImplOptions.NoInlining)]
1218  [CLSCompliant(false)]
1219  public static uint VolatileRead(ref uint address)
1220  {
1221  uint result = address;
1222  MemoryBarrier();
1223  return result;
1224  }
1225 
1229  [MethodImpl(MethodImplOptions.NoInlining)]
1230  public static IntPtr VolatileRead(ref IntPtr address)
1231  {
1232  IntPtr result = address;
1233  MemoryBarrier();
1234  return result;
1235  }
1236 
1240  [MethodImpl(MethodImplOptions.NoInlining)]
1241  [CLSCompliant(false)]
1242  public static UIntPtr VolatileRead(ref UIntPtr address)
1243  {
1244  UIntPtr result = address;
1245  MemoryBarrier();
1246  return result;
1247  }
1248 
1252  [MethodImpl(MethodImplOptions.NoInlining)]
1253  [CLSCompliant(false)]
1254  public static ulong VolatileRead(ref ulong address)
1255  {
1256  ulong result = address;
1257  MemoryBarrier();
1258  return result;
1259  }
1260 
1264  [MethodImpl(MethodImplOptions.NoInlining)]
1265  public static float VolatileRead(ref float address)
1266  {
1267  float result = address;
1268  MemoryBarrier();
1269  return result;
1270  }
1271 
1275  [MethodImpl(MethodImplOptions.NoInlining)]
1276  public static double VolatileRead(ref double address)
1277  {
1278  double result = address;
1279  MemoryBarrier();
1280  return result;
1281  }
1282 
1286  [MethodImpl(MethodImplOptions.NoInlining)]
1287  public static object VolatileRead(ref object address)
1288  {
1289  object result = address;
1290  MemoryBarrier();
1291  return result;
1292  }
1293 
1297  [MethodImpl(MethodImplOptions.NoInlining)]
1298  public static void VolatileWrite(ref byte address, byte value)
1299  {
1300  MemoryBarrier();
1301  address = value;
1302  }
1303 
1307  [MethodImpl(MethodImplOptions.NoInlining)]
1308  public static void VolatileWrite(ref short address, short value)
1309  {
1310  MemoryBarrier();
1311  address = value;
1312  }
1313 
1317  [MethodImpl(MethodImplOptions.NoInlining)]
1318  public static void VolatileWrite(ref int address, int value)
1319  {
1320  MemoryBarrier();
1321  address = value;
1322  }
1323 
1327  [MethodImpl(MethodImplOptions.NoInlining)]
1328  public static void VolatileWrite(ref long address, long value)
1329  {
1330  MemoryBarrier();
1331  address = value;
1332  }
1333 
1337  [MethodImpl(MethodImplOptions.NoInlining)]
1338  [CLSCompliant(false)]
1339  public static void VolatileWrite(ref sbyte address, sbyte value)
1340  {
1341  MemoryBarrier();
1342  address = value;
1343  }
1344 
1348  [MethodImpl(MethodImplOptions.NoInlining)]
1349  [CLSCompliant(false)]
1350  public static void VolatileWrite(ref ushort address, ushort value)
1351  {
1352  MemoryBarrier();
1353  address = value;
1354  }
1355 
1359  [MethodImpl(MethodImplOptions.NoInlining)]
1360  [CLSCompliant(false)]
1361  public static void VolatileWrite(ref uint address, uint value)
1362  {
1363  MemoryBarrier();
1364  address = value;
1365  }
1366 
1370  [MethodImpl(MethodImplOptions.NoInlining)]
1371  public static void VolatileWrite(ref IntPtr address, IntPtr value)
1372  {
1373  MemoryBarrier();
1374  address = value;
1375  }
1376 
1380  [MethodImpl(MethodImplOptions.NoInlining)]
1381  [CLSCompliant(false)]
1382  public static void VolatileWrite(ref UIntPtr address, UIntPtr value)
1383  {
1384  MemoryBarrier();
1385  address = value;
1386  }
1387 
1391  [MethodImpl(MethodImplOptions.NoInlining)]
1392  [CLSCompliant(false)]
1393  public static void VolatileWrite(ref ulong address, ulong value)
1394  {
1395  MemoryBarrier();
1396  address = value;
1397  }
1398 
1402  [MethodImpl(MethodImplOptions.NoInlining)]
1403  public static void VolatileWrite(ref float address, float value)
1404  {
1405  MemoryBarrier();
1406  address = value;
1407  }
1408 
1412  [MethodImpl(MethodImplOptions.NoInlining)]
1413  public static void VolatileWrite(ref double address, double value)
1414  {
1415  MemoryBarrier();
1416  address = value;
1417  }
1418 
1422  [MethodImpl(MethodImplOptions.NoInlining)]
1423  public static void VolatileWrite(ref object address, object value)
1424  {
1425  MemoryBarrier();
1426  address = value;
1427  }
1428 
1430  [MethodImpl(MethodImplOptions.InternalCall)]
1431  [SecuritySafeCritical]
1432  [__DynamicallyInvokable]
1433  public static extern void MemoryBarrier();
1434 
1438  void _Thread.GetTypeInfoCount(out uint pcTInfo)
1439  {
1440  throw new NotImplementedException();
1441  }
1442 
1448  void _Thread.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
1449  {
1450  throw new NotImplementedException();
1451  }
1452 
1460  void _Thread.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1461  {
1462  throw new NotImplementedException();
1463  }
1464 
1475  void _Thread.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1476  {
1477  throw new NotImplementedException();
1478  }
1479 
1480  [MethodImpl(MethodImplOptions.InternalCall)]
1481  [SecurityCritical]
1482  internal extern void SetAbortReason(object o);
1483 
1484  [MethodImpl(MethodImplOptions.InternalCall)]
1485  [SecurityCritical]
1486  internal extern object GetAbortReason();
1487 
1488  [MethodImpl(MethodImplOptions.InternalCall)]
1489  [SecurityCritical]
1490  internal extern void ClearAbortReason();
1491  }
1492 }
static Thread CurrentThread
Gets the currently running thread.
Definition: Thread.cs:134
bool IsBackground
Gets or sets a value indicating whether or not a thread is a background thread.
Definition: Thread.cs:149
static IPrincipal CurrentPrincipal
Gets or sets the thread's current principal (for role-based security).
Definition: Thread.cs:297
A platform-specific type that is used to represent a pointer or a handle.
Definition: UIntPtr.cs:14
bool IsThreadPoolThread
Gets a value indicating whether or not a thread belongs to the managed thread pool.
Definition: Thread.cs:124
static void VolatileWrite(ref byte address, byte value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1298
void DisableComObjectEagerCleanup()
Turns off automatic cleanup of runtime callable wrappers (RCW) for the current thread.
static CultureInfo DefaultThreadCurrentUICulture
Gets or sets the default UI culture for threads in the current application domain.
Definition: CultureInfo.cs:240
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
delegate void ParameterizedThreadStart(object obj)
Represents the method that executes on a T:System.Threading.Thread.
ThreadPriority
Specifies the scheduling priority of a T:System.Threading.Thread.
bool Join(TimeSpan timeout)
Blocks the calling thread until the thread represented by this instance terminates or the specified t...
Definition: Thread.cs:728
Ability to use certain advanced operations on threads.
static void MemoryBarrier()
Synchronizes memory access as follows: The processor executing the current thread cannot reorder inst...
Encapsulates a memory slot to store local data. This class cannot be inherited.
static Context DefaultContext
Gets the default context for the current application domain.
Definition: Context.cs:78
Defines the basic functionality of a principal object.
Definition: IPrincipal.cs:8
static int VolatileRead(ref int address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1172
CompressedStack GetCompressedStack()
Returns a T:System.Threading.CompressedStack object that can be used to capture the stack for the cur...
Definition: Thread.cs:586
bool TrySetApartmentState(ApartmentState state)
Sets the apartment state of a thread before it is started.
Definition: Thread.cs:890
The exception that is thrown when a T:System.Threading.Thread is in an invalid P:System....
Ensures that all finalization code in derived classes is marked as critical.
static LocalDataStoreSlot GetNamedDataSlot(string name)
Looks up a named data slot. For better performance, use fields that are marked with the T:System....
Definition: Thread.cs:960
static sbyte Min(sbyte val1, sbyte val2)
Returns the smaller of two 8-bit signed integers.
Definition: Math.cs:762
Definition: __Canon.cs:3
ThreadState ThreadState
Gets a value containing the states of the current thread.
Definition: Thread.cs:166
static double VolatileRead(ref double address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1276
delegate void ThreadStart()
Represents the method that executes on a T:System.Threading.Thread.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static void Sleep(TimeSpan timeout)
Suspends the current thread for the specified amount of time.
Definition: Thread.cs:758
static float VolatileRead(ref float address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1265
void Join()
Blocks the calling thread until the thread represented by this instance terminates,...
Definition: Thread.cs:703
double TotalMilliseconds
Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional milliseco...
Definition: TimeSpan.cs:180
object Target
Gets the class instance on which the current delegate invokes the instance method.
Definition: Delegate.cs:46
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
static IntPtr VolatileRead(ref IntPtr address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1230
Defines an environment for the objects that are resident inside it and for which a policy can be enfo...
Definition: Context.cs:14
Exposes the T:System.Threading.Thread class to unmanaged code.
Definition: _Thread.cs:11
static ulong VolatileRead(ref ulong address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1254
void Resume()
Resumes a thread that has been suspended.
Definition: Thread.cs:664
static CultureInfo DefaultThreadCurrentCulture
Gets or sets the default culture for threads in the current application domain.
Definition: CultureInfo.cs:220
Represents an application domain, which is an isolated environment where applications execute....
Definition: AppDomain.cs:33
void SetCompressedStack(CompressedStack stack)
Applies a captured T:System.Threading.CompressedStack to the current thread.
Definition: Thread.cs:565
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
Thread(ThreadStart start, int maxStackSize)
Initializes a new instance of the T:System.Threading.Thread class, specifying the maximum stack size ...
Definition: Thread.cs:409
static LocalDataStoreSlot AllocateDataSlot()
Allocates an unnamed data slot on all the threads. For better performance, use fields that are marked...
Definition: Thread.cs:941
static short VolatileRead(ref short address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1161
static byte VolatileRead(ref byte address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1150
override int GetHashCode()
Returns a hash code for the current thread.
Definition: Thread.cs:460
SecurityAction
Specifies the security actions that can be performed using declarative security.
CultureInfo?? CurrentCulture
Gets or sets the culture for the current thread.
Definition: Thread.cs:245
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Manages the execution context for the current thread. This class cannot be inherited.
static void VolatileWrite(ref IntPtr address, IntPtr value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1371
static void ResetAbort()
Cancels an M:System.Threading.Thread.Abort(System.Object) requested for the current thread.
Definition: Thread.cs:627
ApartmentState GetApartmentState()
Returns an T:System.Threading.ApartmentState value indicating the apartment state.
Definition: Thread.cs:876
ApartmentState ApartmentState
Gets or sets the apartment state of this thread.
Definition: Thread.cs:179
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Provides a set of properties that are carried with the execution code path. This class cannot be inhe...
Definition: CallContext.cs:12
static void BeginCriticalRegion()
Notifies a host that execution is about to enter a region of code in which the effects of a thread ab...
Defines the underlying structure of all code access permissions.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
void Abort()
Raises a T:System.Threading.ThreadAbortException in the thread on which it is invoked,...
Definition: Thread.cs:612
static object VolatileRead(ref object address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1287
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: Delegate.cs:15
static ushort VolatileRead(ref ushort address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1207
Thread(ThreadStart start)
Initializes a new instance of the T:System.Threading.Thread class.
Definition: Thread.cs:392
bool IsAlive
Gets a value indicating the execution status of the current thread.
Definition: Thread.cs:114
void Start(object parameter)
Causes the operating system to change the state of the current instance to F:System....
Definition: Thread.cs:493
static void VolatileWrite(ref long address, long value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1328
void SetApartmentState(ApartmentState state)
Sets the apartment state of a thread before it is started.
Definition: Thread.cs:903
MethodImplOptions
Defines the details of how a method is implemented.
static AppDomain GetDomain()
Returns the current domain in which the current thread is running.
Definition: Thread.cs:1096
static void VolatileWrite(ref UIntPtr address, UIntPtr value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1382
Manipulates threads in a way that only affects user code.
static void BeginThreadAffinity()
Notifies a host that managed code is about to execute instructions that depend on the identity of the...
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
static void EndCriticalRegion()
Notifies a host that execution is about to enter a region of code in which the effects of a thread ab...
T Value
Gets or sets the value of the ambient data.
Definition: AsyncLocal.cs:17
void Start()
Causes the operating system to change the state of the current instance to F:System....
Definition: Thread.cs:480
void Abort(object stateInfo)
Raises a T:System.Threading.ThreadAbortException in the thread on which it is invoked,...
Definition: Thread.cs:601
ThreadPriority Priority
Gets or sets a value indicating the scheduling priority of a thread.
Definition: Thread.cs:96
static ExecutionContext Capture()
Captures the execution context from the current thread.
static void VolatileWrite(ref int address, int value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1318
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
static sbyte VolatileRead(ref sbyte address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1195
static void VolatileWrite(ref object address, object value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1423
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
static void VolatileWrite(ref sbyte address, sbyte value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1339
static void VolatileWrite(ref ulong address, ulong value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1393
static void VolatileWrite(ref uint address, uint value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1361
int ManagedThreadId
Gets a unique identifier for the current managed thread.
Definition: Thread.cs:55
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
static void VolatileWrite(ref ushort address, ushort value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1350
bool Join(int millisecondsTimeout)
Blocks the calling thread until the thread represented by this instance terminates or the specified t...
Definition: Thread.cs:716
static LocalDataStoreSlot AllocateNamedDataSlot(string name)
Allocates a named data slot on all threads. For better performance, use fields that are marked with t...
Definition: Thread.cs:951
Creates or manipulates threads other than its own, which might be harmful to the host.
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
static UIntPtr VolatileRead(ref UIntPtr address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1242
Provides methods for setting and capturing the compressed stack on the current thread....
Thread(ParameterizedThreadStart start, int maxStackSize)
Initializes a new instance of the T:System.Threading.Thread class, specifying a delegate that allows ...
Definition: Thread.cs:444
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
static void EndThreadAffinity()
Notifies a host that managed code has finished executing instructions that depend on the identity of ...
static void FreeNamedDataSlot(string name)
Eliminates the association between a name and a slot, for all threads in the process....
Definition: Thread.cs:968
static void SetData(LocalDataStoreSlot slot, object data)
Sets the data in the specified slot on the currently running thread, for that thread's current domain...
Definition: Thread.cs:992
static uint VolatileRead(ref uint address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1219
static void VolatileWrite(ref float address, float value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1403
The exception that is thrown when a method call is invalid for the object's current state.
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
void Interrupt()
Interrupts a thread that is in the WaitSleepJoin thread state.
Definition: Thread.cs:677
Thread(ParameterizedThreadStart start)
Initializes a new instance of the T:System.Threading.Thread class, specifying a delegate that allows ...
Definition: Thread.cs:427
static int GetDomainID()
Returns a unique application domain identifier.
Definition: Thread.cs:1108
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
Definition: Math.cs:10
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
static object GetData(LocalDataStoreSlot slot)
Retrieves the value from the specified slot on the current thread, within the current thread's curren...
Definition: Thread.cs:977
string??? Name
Gets or sets the name of the thread.
Definition: Thread.cs:323
SecurityPermissionFlag
Specifies access flags for the security permission object.
static void VolatileWrite(ref short address, short value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1308
static void Sleep(int millisecondsTimeout)
Suspends the current thread for the specified number of milliseconds.
Definition: Thread.cs:746
ThreadState
Specifies the execution states of a T:System.Threading.Thread.
Definition: ThreadState.cs:9
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
static Context CurrentContext
Gets the current context in which the thread is executing.
Definition: Thread.cs:285
The exception that is thrown when a requested method or operation is not implemented.
The exception that is thrown when a security error is detected.
ExecutionContext ExecutionContext
Gets an T:System.Threading.ExecutionContext object that contains information about the various contex...
Definition: Thread.cs:78
ApartmentState
Specifies the apartment state of a T:System.Threading.Thread.
static long VolatileRead(ref long address)
Reads the value of a field. The value is the latest written by any processor in a computer,...
Definition: Thread.cs:1183
static bool Yield()
Causes the calling thread to yield execution to another thread that is ready to run on the current pr...
Definition: Thread.cs:797
CultureInfo?? CurrentUICulture
Gets or sets the current culture used by the Resource Manager to look up culture-specific resources a...
Definition: Thread.cs:199
static void VolatileWrite(ref double address, double value)
Writes a value to a field immediately, so that the value is visible to all processors in the computer...
Definition: Thread.cs:1413
void Suspend()
Either suspends the thread, or if the thread is already suspended, has no effect.
Definition: Thread.cs:649
static void SpinWait(int iterations)
Causes a thread to wait the number of times defined by the iterations parameter.
Definition: Thread.cs:779
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18