private void ThreadMain() { CurrentContext = this; mThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; OnThreadStart(); while (mIsRun) { var time1 = Support.Time.GetTickCount(); try { Tick(); } catch (Exception ex) { Profiler.Log.WriteException(ex); } finally { ContextThread.CurrentContext.ExitWhenFrameFinished(); } var time2 = Support.Time.GetTickCount(); if (time2 - time1 < Interval) { System.Threading.Thread.Sleep(Interval - (int)(time2 - time1)); } } mIsFinished = true; OnThreadExited(); CurrentContext = null; }
public void FromCurrent(string name) { if (mThreadId == 0) { mThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId; if (CurrentContext == null) { CurrentContext = this; } mIsRun = true; this.Name = name; } this.OnThreadStart(); }