2 // System.Threading.Thread.cs
5 // Dick Porter (dick@ximian.com)
7 // (C) Ximian, Inc. http://www.ximian.com
8 // Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Runtime.Remoting.Contexts;
31 using System.Runtime.Serialization;
32 using System.Runtime.Serialization.Formatters.Binary;
33 using System.Security.Permissions;
34 using System.Security.Principal;
35 using System.Globalization;
36 using System.Runtime.CompilerServices;
37 using System.Runtime.InteropServices;
39 using System.Collections;
40 using System.Security;
43 using System.Runtime.ConstrainedExecution;
46 namespace System.Threading {
48 [ClassInterface (ClassInterfaceType.None)]
51 [ComDefaultInterface (typeof (_Thread))]
52 public sealed class Thread : CriticalFinalizerObject, _Thread {
54 public sealed class Thread : _Thread {
57 #region Sync with metadata/object-internals.h
59 // stores a thread handle
60 private IntPtr system_thread_handle;
62 /* Note this is an opaque object (an array), not a CultureInfo */
63 private object cached_culture_info;
64 private IntPtr unused0;
65 private bool threadpool_thread;
66 /* accessed only from unmanaged code */
69 private ThreadState state = ThreadState.Unstarted;
70 private object abort_exc;
71 internal object abort_state;
72 /* thread_id is only accessed from unmanaged code */
73 private Int64 thread_id;
75 /* start_notify is used by the runtime to signal that Start()
78 private IntPtr start_notify;
79 private IntPtr stack_ptr;
80 private UIntPtr static_data; /* GC-tracked */
81 private IntPtr jit_data;
82 private IntPtr lock_data;
83 Context current_appcontext;
86 private IntPtr appdomain_refs;
87 private bool interruption_requested;
88 private IntPtr suspend_event;
89 private IntPtr suspended_event;
90 private IntPtr resume_event;
91 /* Don't lock on synch_cs in managed code, since it can result in deadlocks */
92 private object synch_cs = null;
93 private IntPtr serialized_culture_info;
94 private int serialized_culture_info_len;
95 private IntPtr serialized_ui_culture_info;
96 private int serialized_ui_culture_info_len;
97 private ExecutionContext _ec;
98 private bool thread_dump_requested;
99 private IntPtr end_stack;
100 private bool thread_interrupt_requested;
101 private byte apartment_state = (byte)ApartmentState.Unknown;
103 * These fields are used to avoid having to increment corlib versions
104 * when a new field is added to the unmanaged MonoThread structure.
106 private IntPtr unused5;
107 private IntPtr unused6;
108 private IntPtr unused7;
111 // the name of local_slots is important as it's used by the runtime.
113 static object[] local_slots;
115 // can be both a ThreadSart and a ParameterizedThreadStart
116 private MulticastDelegate threadstart;
117 private string thread_name=null;
119 private static int _managed_id_counter;
120 private int managed_id;
122 private IPrincipal _principal;
124 public static Context CurrentContext {
125 [SecurityPermission (SecurityAction.LinkDemand, Infrastructure=true)]
127 return(AppDomain.InternalGetContext ());
131 public static IPrincipal CurrentPrincipal {
134 Thread th = CurrentThread;
138 p = GetDomain ().DefaultPrincipal;
144 [SecurityPermission (SecurityAction.Demand, ControlPrincipal = true)]
146 CurrentThread._principal = value;
150 // Looks up the object associated with the current thread
151 [MethodImplAttribute(MethodImplOptions.InternalCall)]
152 private extern static Thread CurrentThread_internal();
154 public static Thread CurrentThread {
156 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
159 return(CurrentThread_internal());
163 internal static int CurrentThreadId {
165 return (int)(CurrentThread.thread_id);
169 // Stores a hash keyed by strings of LocalDataStoreSlot objects
170 static Hashtable datastorehash;
171 private static object datastore_lock = new object ();
173 private static void InitDataStoreHash () {
174 lock (datastore_lock) {
175 if (datastorehash == null) {
176 datastorehash = Hashtable.Synchronized(new Hashtable());
181 public static LocalDataStoreSlot AllocateNamedDataSlot (string name) {
182 lock (datastore_lock) {
183 if (datastorehash == null)
184 InitDataStoreHash ();
185 LocalDataStoreSlot slot = (LocalDataStoreSlot)datastorehash [name];
187 // This exception isnt documented (of
188 // course) but .net throws it
189 throw new ArgumentException("Named data slot already added");
192 slot = AllocateDataSlot ();
194 datastorehash.Add (name, slot);
200 public static void FreeNamedDataSlot (string name) {
201 lock (datastore_lock) {
202 if (datastorehash == null)
203 InitDataStoreHash ();
204 LocalDataStoreSlot slot = (LocalDataStoreSlot)datastorehash [name];
207 datastorehash.Remove (slot);
212 public static LocalDataStoreSlot AllocateDataSlot () {
213 return new LocalDataStoreSlot (true);
216 public static object GetData (LocalDataStoreSlot slot) {
217 object[] slots = local_slots;
219 throw new ArgumentNullException ("slot");
220 if (slots != null && slot.slot < slots.Length)
221 return slots [slot.slot];
225 public static void SetData (LocalDataStoreSlot slot, object data) {
226 object[] slots = local_slots;
228 throw new ArgumentNullException ("slot");
230 slots = new object [slot.slot + 2];
232 } else if (slot.slot >= slots.Length) {
233 object[] nslots = new object [slot.slot + 2];
234 slots.CopyTo (nslots, 0);
238 slots [slot.slot] = data;
241 public static AppDomain GetDomain() {
242 return AppDomain.CurrentDomain;
245 [MethodImplAttribute(MethodImplOptions.InternalCall)]
246 public extern static int GetDomainID();
248 [MethodImplAttribute (MethodImplOptions.InternalCall)]
249 internal extern static void FreeLocalSlotValues (int slot, bool thread_local);
251 public static LocalDataStoreSlot GetNamedDataSlot(string name) {
252 lock (datastore_lock) {
253 if (datastorehash == null)
254 InitDataStoreHash ();
255 LocalDataStoreSlot slot=(LocalDataStoreSlot)datastorehash[name];
258 slot=AllocateNamedDataSlot(name);
265 [MethodImplAttribute(MethodImplOptions.InternalCall)]
266 private extern static void ResetAbort_internal();
268 [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
269 public static void ResetAbort ()
271 ResetAbort_internal ();
274 [MethodImplAttribute(MethodImplOptions.InternalCall)]
275 private extern static void Sleep_internal(int ms);
277 public static void Sleep(int millisecondsTimeout) {
278 if((millisecondsTimeout<0) && (millisecondsTimeout != Timeout.Infinite)) {
279 throw new ArgumentException("Negative timeout");
281 Sleep_internal(millisecondsTimeout);
284 public static void Sleep(TimeSpan timeout) {
285 // LAMESPEC: says to throw ArgumentException too
286 int ms=Convert.ToInt32(timeout.TotalMilliseconds);
288 if(ms < 0 || ms > Int32.MaxValue) {
289 throw new ArgumentOutOfRangeException("Timeout out of range");
295 // Returns the system thread handle
296 [MethodImplAttribute(MethodImplOptions.InternalCall)]
297 private extern IntPtr Thread_internal (MulticastDelegate start);
299 [MethodImplAttribute(MethodImplOptions.InternalCall)]
300 private extern void Thread_init ();
302 private static int GetNewManagedId() {
303 return Interlocked.Increment(ref _managed_id_counter);
306 public Thread(ThreadStart start) {
308 throw new ArgumentNullException("Null ThreadStart");
316 [Obsolete ("Deprecated in favor of GetApartmentState, SetApartmentState and TrySetApartmentState.")]
318 public ApartmentState ApartmentState {
320 if ((ThreadState & ThreadState.Stopped) != 0)
321 throw new ThreadStateException ("Thread is dead; state can not be accessed.");
323 return (ApartmentState)apartment_state;
328 TrySetApartmentState (value);
330 if ((ThreadState & ThreadState.Unstarted) == 0)
331 throw new ThreadStateException ("Thread was in an invalid state for the operation being executed.");
333 if (value != ApartmentState.STA && value != ApartmentState.MTA)
334 throw new ArgumentException ("value is not a valid apartment state.");
336 if ((ApartmentState)apartment_state == ApartmentState.Unknown)
337 apartment_state = (byte)value;
342 [MethodImplAttribute (MethodImplOptions.InternalCall)]
343 private static extern int current_lcid ();
345 [MethodImplAttribute (MethodImplOptions.InternalCall)]
346 private extern CultureInfo GetCachedCurrentCulture ();
348 [MethodImplAttribute (MethodImplOptions.InternalCall)]
349 private extern byte[] GetSerializedCurrentCulture ();
351 [MethodImplAttribute (MethodImplOptions.InternalCall)]
352 private extern void SetCachedCurrentCulture (CultureInfo culture);
354 [MethodImplAttribute (MethodImplOptions.InternalCall)]
355 private extern void SetSerializedCurrentCulture (byte[] culture);
357 [MethodImplAttribute (MethodImplOptions.InternalCall)]
358 private extern CultureInfo GetCachedCurrentUICulture ();
360 [MethodImplAttribute (MethodImplOptions.InternalCall)]
361 private extern byte[] GetSerializedCurrentUICulture ();
363 [MethodImplAttribute (MethodImplOptions.InternalCall)]
364 private extern void SetCachedCurrentUICulture (CultureInfo culture);
366 [MethodImplAttribute (MethodImplOptions.InternalCall)]
367 private extern void SetSerializedCurrentUICulture (byte[] culture);
369 /* If the current_lcid() isn't known by CultureInfo,
370 * it will throw an exception which may cause
371 * String.Concat to try and recursively look up the
372 * CurrentCulture, which will throw an exception, etc.
373 * Use a boolean to short-circuit this scenario.
375 private static bool in_currentculture=false;
377 static object culture_lock = new object ();
380 * Thread objects are shared between appdomains, and CurrentCulture
381 * should always return an object in the calling appdomain. See bug
382 * http://bugzilla.ximian.com/show_bug.cgi?id=50049 for more info.
383 * This is hard to implement correctly and efficiently, so the current
384 * implementation is not perfect: changes made in one appdomain to the
385 * state of the current cultureinfo object are not visible to other
388 public CultureInfo CurrentCulture {
390 if (in_currentculture)
392 return CultureInfo.InvariantCulture;
394 CultureInfo culture = GetCachedCurrentCulture ();
398 byte[] arr = GetSerializedCurrentCulture ();
400 lock (culture_lock) {
401 in_currentculture=true;
402 culture = CultureInfo.ConstructCurrentCulture ();
404 // Don't serialize the culture in this case to avoid
405 // initializing the serialization infrastructure in the
406 // common case when the culture is not set explicitly.
408 SetCachedCurrentCulture (culture);
409 in_currentculture = false;
415 * No cultureinfo object exists for this domain, so create one
416 * by deserializing the serialized form.
418 in_currentculture = true;
420 BinaryFormatter bf = new BinaryFormatter ();
421 MemoryStream ms = new MemoryStream (arr);
422 culture = (CultureInfo)bf.Deserialize (ms);
423 SetCachedCurrentCulture (culture);
425 in_currentculture = false;
431 [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
434 throw new ArgumentNullException ("value");
436 value.CheckNeutral ();
437 in_currentculture = true;
439 BinaryFormatter bf = new BinaryFormatter();
440 MemoryStream ms = new MemoryStream ();
441 bf.Serialize (ms, value);
443 SetCachedCurrentCulture (value);
444 SetSerializedCurrentCulture (ms.GetBuffer ());
446 in_currentculture = false;
451 public CultureInfo CurrentUICulture {
453 if (in_currentculture)
455 return CultureInfo.InvariantCulture;
457 CultureInfo culture = GetCachedCurrentUICulture ();
461 byte[] arr = GetSerializedCurrentUICulture ();
463 lock (culture_lock) {
464 in_currentculture=true;
471 culture = CultureInfo.ConstructCurrentUICulture ();
473 // Don't serialize the culture in this case to avoid
474 // initializing the serialization infrastructure in the
475 // common case when the culture is not set explicitly.
477 SetCachedCurrentUICulture (culture);
478 in_currentculture = false;
484 * No cultureinfo object exists for this domain, so create one
485 * by deserializing the serialized form.
487 in_currentculture = true;
489 BinaryFormatter bf = new BinaryFormatter ();
490 MemoryStream ms = new MemoryStream (arr);
491 culture = (CultureInfo)bf.Deserialize (ms);
492 SetCachedCurrentUICulture (culture);
495 in_currentculture = false;
502 in_currentculture = true;
505 throw new ArgumentNullException ("value");
508 BinaryFormatter bf = new BinaryFormatter();
509 MemoryStream ms = new MemoryStream ();
510 bf.Serialize (ms, value);
512 SetCachedCurrentUICulture (value);
513 SetSerializedCurrentUICulture (ms.GetBuffer ());
515 in_currentculture = false;
520 public bool IsThreadPoolThread {
522 return IsThreadPoolThreadInternal;
526 internal bool IsThreadPoolThreadInternal {
528 return threadpool_thread;
531 threadpool_thread = value;
535 public bool IsAlive {
537 ThreadState curstate = GetState ();
539 if((curstate & ThreadState.Aborted) != 0 ||
540 (curstate & ThreadState.Stopped) != 0 ||
541 (curstate & ThreadState.Unstarted) != 0) {
549 public bool IsBackground {
551 ThreadState thread_state = GetState ();
552 if ((thread_state & ThreadState.Stopped) != 0)
553 throw new ThreadStateException ("Thread is dead; state can not be accessed.");
555 return (thread_state & ThreadState.Background) != 0;
560 SetState (ThreadState.Background);
562 ClrState (ThreadState.Background);
567 [MethodImplAttribute(MethodImplOptions.InternalCall)]
568 private extern string GetName_internal ();
570 [MethodImplAttribute(MethodImplOptions.InternalCall)]
571 private extern void SetName_internal (String name);
574 * The thread name must be shared by appdomains, so it is stored in
580 return GetName_internal ();
584 SetName_internal (value);
588 public ThreadPriority Priority {
590 return(ThreadPriority.Lowest);
594 // FIXME: Implement setter.
598 public ThreadState ThreadState {
604 [MethodImplAttribute(MethodImplOptions.InternalCall)]
605 private extern void Abort_internal (object stateInfo);
607 [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
610 Abort_internal (null);
613 [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
614 public void Abort (object stateInfo)
616 Abort_internal (stateInfo);
619 [MethodImplAttribute (MethodImplOptions.InternalCall)]
620 private extern void Interrupt_internal ();
622 [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
623 public void Interrupt ()
625 Interrupt_internal ();
628 // The current thread joins with 'this'. Set ms to 0 to block
629 // until this actually exits.
630 [MethodImplAttribute(MethodImplOptions.InternalCall)]
631 private extern bool Join_internal(int ms, IntPtr handle);
635 Join_internal(Timeout.Infinite, system_thread_handle);
638 public bool Join(int millisecondsTimeout)
640 if (millisecondsTimeout != Timeout.Infinite && millisecondsTimeout < 0)
641 throw new ArgumentException ("Timeout less than zero", "millisecondsTimeout");
643 return Join_internal(millisecondsTimeout, system_thread_handle);
646 public bool Join(TimeSpan timeout)
648 // LAMESPEC: says to throw ArgumentException too
649 int ms=Convert.ToInt32(timeout.TotalMilliseconds);
651 if(ms < 0 || ms > Int32.MaxValue) {
652 throw new ArgumentOutOfRangeException("timeout out of range");
654 return Join_internal(ms, system_thread_handle);
658 [MethodImplAttribute(MethodImplOptions.InternalCall)]
659 public extern static void MemoryBarrier ();
661 [MethodImplAttribute(MethodImplOptions.InternalCall)]
662 private extern void Resume_internal();
667 [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
668 public void Resume ()
673 [MethodImplAttribute (MethodImplOptions.InternalCall)]
674 private extern static void SpinWait_internal (int iterations);
678 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
680 public static void SpinWait (int iterations)
682 SpinWait_internal (iterations);
685 public void Start() {
686 // propagate informations from the original thread to the new thread
688 if (!ExecutionContext.IsFlowSuppressed ())
689 _ec = ExecutionContext.Capture ();
691 // before 2.0 this was only used for security (mostly CAS) so we
692 // do this only if the security manager is active
693 if (SecurityManager.SecurityEnabled)
694 _ec = ExecutionContext.Capture ();
696 if (CurrentThread._principal != null)
697 _principal = CurrentThread._principal;
699 // Thread_internal creates and starts the new thread,
700 if (Thread_internal(threadstart) == (IntPtr) 0)
701 throw new SystemException ("Thread creation failed.");
704 [MethodImplAttribute(MethodImplOptions.InternalCall)]
705 private extern void Suspend_internal();
710 [SecurityPermission (SecurityAction.Demand, ControlThread=true)]
711 public void Suspend ()
716 // Closes the system thread handle
717 [MethodImplAttribute(MethodImplOptions.InternalCall)]
718 private extern void Thread_free_internal(IntPtr handle);
721 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
724 // Free up the handle
725 if (system_thread_handle != (IntPtr) 0)
726 Thread_free_internal(system_thread_handle);
729 [MethodImplAttribute (MethodImplOptions.InternalCall)]
730 extern private void SetState (ThreadState set);
732 [MethodImplAttribute (MethodImplOptions.InternalCall)]
733 extern private void ClrState (ThreadState clr);
735 [MethodImplAttribute (MethodImplOptions.InternalCall)]
736 extern private ThreadState GetState ();
740 [MethodImplAttribute (MethodImplOptions.InternalCall)]
741 extern public static byte VolatileRead (ref byte address);
743 [MethodImplAttribute (MethodImplOptions.InternalCall)]
744 extern public static double VolatileRead (ref double address);
746 [MethodImplAttribute (MethodImplOptions.InternalCall)]
747 extern public static short VolatileRead (ref short address);
749 [MethodImplAttribute (MethodImplOptions.InternalCall)]
750 extern public static int VolatileRead (ref int address);
752 [MethodImplAttribute (MethodImplOptions.InternalCall)]
753 extern public static long VolatileRead (ref long address);
755 [MethodImplAttribute (MethodImplOptions.InternalCall)]
756 extern public static IntPtr VolatileRead (ref IntPtr address);
758 [MethodImplAttribute (MethodImplOptions.InternalCall)]
759 extern public static object VolatileRead (ref object address);
761 [CLSCompliant(false)]
762 [MethodImplAttribute (MethodImplOptions.InternalCall)]
763 extern public static sbyte VolatileRead (ref sbyte address);
765 [MethodImplAttribute (MethodImplOptions.InternalCall)]
766 extern public static float VolatileRead (ref float address);
768 [CLSCompliant (false)]
769 [MethodImplAttribute (MethodImplOptions.InternalCall)]
770 extern public static ushort VolatileRead (ref ushort address);
772 [CLSCompliant (false)]
773 [MethodImplAttribute (MethodImplOptions.InternalCall)]
774 extern public static uint VolatileRead (ref uint address);
776 [CLSCompliant (false)]
777 [MethodImplAttribute (MethodImplOptions.InternalCall)]
778 extern public static ulong VolatileRead (ref ulong address);
780 [CLSCompliant (false)]
781 [MethodImplAttribute (MethodImplOptions.InternalCall)]
782 extern public static UIntPtr VolatileRead (ref UIntPtr address);
784 [MethodImplAttribute (MethodImplOptions.InternalCall)]
785 extern public static void VolatileWrite (ref byte address, byte value);
787 [MethodImplAttribute (MethodImplOptions.InternalCall)]
788 extern public static void VolatileWrite (ref double address, double value);
790 [MethodImplAttribute (MethodImplOptions.InternalCall)]
791 extern public static void VolatileWrite (ref short address, short value);
793 [MethodImplAttribute (MethodImplOptions.InternalCall)]
794 extern public static void VolatileWrite (ref int address, int value);
796 [MethodImplAttribute (MethodImplOptions.InternalCall)]
797 extern public static void VolatileWrite (ref long address, long value);
799 [MethodImplAttribute (MethodImplOptions.InternalCall)]
800 extern public static void VolatileWrite (ref IntPtr address, IntPtr value);
802 [MethodImplAttribute (MethodImplOptions.InternalCall)]
803 extern public static void VolatileWrite (ref object address, object value);
805 [CLSCompliant(false)]
806 [MethodImplAttribute (MethodImplOptions.InternalCall)]
807 extern public static void VolatileWrite (ref sbyte address, sbyte value);
809 [MethodImplAttribute (MethodImplOptions.InternalCall)]
810 extern public static void VolatileWrite (ref float address, float value);
812 [CLSCompliant (false)]
813 [MethodImplAttribute (MethodImplOptions.InternalCall)]
814 extern public static void VolatileWrite (ref ushort address, ushort value);
816 [CLSCompliant (false)]
817 [MethodImplAttribute (MethodImplOptions.InternalCall)]
818 extern public static void VolatileWrite (ref uint address, uint value);
820 [CLSCompliant (false)]
821 [MethodImplAttribute (MethodImplOptions.InternalCall)]
822 extern public static void VolatileWrite (ref ulong address, ulong value);
824 [CLSCompliant (false)]
825 [MethodImplAttribute (MethodImplOptions.InternalCall)]
826 extern public static void VolatileWrite (ref UIntPtr address, UIntPtr value);
831 public Thread (ThreadStart start, int maxStackSize)
834 throw new ArgumentNullException ("start");
835 if (maxStackSize < 131072)
836 throw new ArgumentException ("< 128 kb", "maxStackSize");
839 stack_size = maxStackSize;
843 public Thread (ParameterizedThreadStart start)
846 throw new ArgumentNullException ("start");
852 public Thread (ParameterizedThreadStart start, int maxStackSize)
855 throw new ArgumentNullException ("start");
856 if (maxStackSize < 131072)
857 throw new ArgumentException ("< 128 kb", "maxStackSize");
860 stack_size = maxStackSize;
864 [MonoTODO ("limited to CompressedStack support")]
865 // FIXME: We share the _ec object between appdomains
866 public ExecutionContext ExecutionContext {
867 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
870 _ec = new ExecutionContext ();
875 public int ManagedThreadId {
876 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.Success)]
878 if (managed_id == 0) {
879 int new_managed_id = GetNewManagedId ();
881 Interlocked.CompareExchange (ref managed_id, new_managed_id, 0);
888 [MonoTODO("Not implemented")]
889 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
890 public static void BeginCriticalRegion ()
892 throw new NotImplementedException ();
895 [MonoTODO("Not implemented")]
896 [ReliabilityContract (Consistency.WillNotCorruptState, Cer.Success)]
897 public static void EndCriticalRegion ()
899 throw new NotImplementedException ();
902 [MonoTODO("Not implemented")]
903 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
904 public static void BeginThreadAffinity ()
906 throw new NotImplementedException ();
909 [MonoTODO("Not implemented")]
910 [ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
911 public static void EndThreadAffinity ()
913 throw new NotImplementedException ();
916 public ApartmentState GetApartmentState ()
918 return (ApartmentState)apartment_state;
921 public void SetApartmentState (ApartmentState state)
923 if (!TrySetApartmentState (state))
924 throw new InvalidOperationException ("Failed to set the specified COM apartment state.");
927 public bool TrySetApartmentState (ApartmentState state)
929 if ((ThreadState & ThreadState.Unstarted) == 0)
930 throw new ThreadStateException ("Thread was in an invalid state for the operation being executed.");
932 if ((ApartmentState)apartment_state != ApartmentState.Unknown)
935 apartment_state = (byte)state;
941 public override int GetHashCode ()
943 return ManagedThreadId;
946 public void Start (object parameter)
948 start_obj = parameter;
952 internal ExecutionContext ExecutionContext {
955 _ec = new ExecutionContext ();
961 // NOTE: This method doesn't show in the class library status page because
962 // it cannot be "found" with the StrongNameIdentityPermission for ECMA key.
964 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
965 [StrongNameIdentityPermission (SecurityAction.LinkDemand, PublicKey="00000000000000000400000000000000")]
967 [Obsolete ("see CompressedStack class")]
974 CompressedStack GetCompressedStack ()
976 // Note: returns null if no CompressedStack has been set.
977 // However CompressedStack.GetCompressedStack returns an
978 // (empty?) CompressedStack instance.
979 CompressedStack cs = ExecutionContext.SecurityContext.CompressedStack;
980 return ((cs == null) || cs.IsEmpty ()) ? null : cs.CreateCopy ();
983 // NOTE: This method doesn't show in the class library status page because
984 // it cannot be "found" with the StrongNameIdentityPermission for ECMA key.
986 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
987 [StrongNameIdentityPermission (SecurityAction.LinkDemand, PublicKey="00000000000000000400000000000000")]
989 [Obsolete ("see CompressedStack class")]
996 void SetCompressedStack (CompressedStack stack)
998 ExecutionContext.SecurityContext.CompressedStack = stack;
1002 void _Thread.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
1004 throw new NotImplementedException ();
1007 void _Thread.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
1009 throw new NotImplementedException ();
1012 void _Thread.GetTypeInfoCount (out uint pcTInfo)
1014 throw new NotImplementedException ();
1017 void _Thread.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams,
1018 IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
1020 throw new NotImplementedException ();