// Blocks the calling thread until a thread terminates or the specified time elapses, // while continuing to perform standard COM and SendMessage pumping. public static bool Join(Original::Thread thread, TimeSpan timespan) { return(Helper.SimpleWrap <bool>( delegate(ClrSyncManager m) { return JoinRaw(thread, m, (int)timespan.TotalMilliseconds); }, delegate() { return thread.Join(timespan); } )); }
public static int get_ManagedThreadId(Original::Thread thread) { return(Helper.SimpleWrap <int>( delegate(ClrSyncManager m) { return 10000 + m.GetChessTask(thread); }, delegate() { return thread.ManagedThreadId; } )); }
// Blocks the calling thread until a thread terminates or the specified time elapses, // while continuing to perform standard COM and SendMessage pumping. public static bool Join(Original::Thread thread, int t) { return(Helper.SimpleWrap <bool>( delegate(ClrSyncManager m) { return JoinRaw(thread, m, t); }, delegate() { return thread.Join(t); } )); }
// Blocks the calling thread until a thread terminates, while continuing to perform standard COM // and SendMessage pumping. public static void Join(Original::Thread thread) { Helper.SimpleWrap <bool>( delegate(ClrSyncManager m) { JoinRaw(thread, m, -1); return(true); }, delegate() { thread.Join(); return(true); } ); }
public static void StartHelper(Original::Thread t, object o, bool parameterized) { Helper.SimpleDel <bool> common = delegate() { if (parameterized) { t.Start(o); } else { t.Start(); } return(false); }; Helper.SimpleWrap <bool>( delegate(ClrSyncManager manager) { ChessTask child = manager.TaskFork(); Original.Semaphore childSem = new Original.Semaphore(0, 1); manager.RegisterTaskSemaphore(child, childSem, true); manager.AddChildHandle(child, t); manager.TaskResume(child); common(); return(false); }, common); }
public static Original::Thread ConstructThread <T>(MakeThreadDelegate <T> mt, T del, WrapThreadStartDelegate <T> wts) { return(Helper.SimpleWrap <Original::Thread>( delegate(ClrSyncManager manager) { // wrap the delegate Original::Thread ret = mt(wts(del, manager)); return ret; }, delegate() { return mt(del); })); }
private static bool JoinRaw(Original::Thread t, ClrSyncManager manager, int millisecondsTimeout) { if (millisecondsTimeout < Timeout.Infinite) { throw new ArgumentOutOfRangeException(); } bool ret; while (true) { manager.SetMethodInfo("Thread.Join(" + millisecondsTimeout + ")"); manager.SyncVarAccess(t, MSyncVarOp.TASK_JOIN); try { ret = t.Join(0); } catch (Exception e) { manager.CommitSyncVarAccess(); throw e; } if (ret) { break; // join succeeded } if (millisecondsTimeout >= 0) { manager.MarkTimeout(); manager.CommitSyncVarAccess(); manager.TaskYield(); return(ret); } manager.LocalBacktrack(); } manager.CommitSyncVarAccess(); return(ret); }
public static void Interrupt(Original::Thread thread) { throw new NotImplementedException("Thread.Interrupt (1)."); }
public static void Abort(Original::Thread thread, object o) { throw new NotImplementedException("Thread.Abort (2). You should avoid using this method. See http://msmvps.com/blogs/peterritchie/archive/2007/08/22/thead-abort-is-a-sign-of-a-poorly-designed-program.aspx for more detail."); }
public static void Resume(Original::Thread thread) { throw new NotImplementedException("Thread.Resume has been deprecated"); }
public static void Suspend(Original::Thread thread) { throw new NotImplementedException("Thread.Suspend has been deprecated"); }
public static void Start(Original::Thread thread, object obj) { Helper.StartHelper(thread, obj, true); }
public static void Start(Original::Thread thread) { Helper.StartHelper(thread, null, false); }