private void updateTextBoxWithState(TextBoxExt textBox, ThreadState state) { switch (state) { case ThreadState.Running: textBox.Text = "alive"; textBox.BackColor = Color.Aquamarine; break; case ThreadState.Aborted: textBox.Text = "aborted"; textBox.BackColor = Color.LightSalmon; break; case ThreadState.Stopped: textBox.Text = "stopped"; textBox.BackColor = Color.LightSalmon; break; case ThreadState.Suspended: textBox.Text = "ignore"; textBox.BackColor = Color.Yellow; break; case ThreadState.SuspendRequested: textBox.Text = "wait for ignore"; textBox.BackColor = Color.Yellow; break; } }
internal string ConvStat() { if (thread.IsAlive == false) { return("dead"); } System.Threading.ThreadState st = thread.ThreadState; if ((st & System.Threading.ThreadState.AbortRequested) != 0) { return("aborting"); } if ((st & (System.Threading.ThreadState.WaitSleepJoin | System.Threading.ThreadState.Stopped | System.Threading.ThreadState.Suspended)) != 0) { return("sleep"); } if (st == System.Threading.ThreadState.Running || (st & (System.Threading.ThreadState.Background | System.Threading.ThreadState.SuspendRequested | System.Threading.ThreadState.StopRequested | System.Threading.ThreadState.Unstarted)) != 0) { return("run"); } return(String.Format("unknown({0})", st.ToString())); }
private static void ReapDeadThreads() { while (true) { NativeThread.Sleep(3000); foreach (var thread in AllThreads) { ThreadState state = thread.ThreadState; if (state == ThreadState.Unstarted) { continue; } if (state == ThreadState.Suspended) { continue; } if (state == ThreadState.WaitSleepJoin) { continue; } if (state == ThreadState.Running) { continue; } DeregisterThread(thread); } } }
private void btn1_Click(object sender, RoutedEventArgs e) { clearComments(); //获取正在运行的线程 Thread thread = Thread.CurrentThread; //设置线程的名字 thread.Name = "主线程"; //获取当前线程的唯一标识符 int id = thread.ManagedThreadId; //获取当前线程的状态 System.Threading.ThreadState state = thread.ThreadState; //获取当前线程的优先级 ThreadPriority priority = thread.Priority; string strMsg = string.Format("Thread ID:{0}\n" + "Thread Name:{1}\n" + "Thread State:{2}\n" + "Thread Priority:{3}\n", id, thread.Name, state, priority); Console.WriteLine(strMsg); //Console.ReadKey(); showComment(strMsg); }
private ServiceThread(SerializationInfo info, StreamingContext context) { this.status = (System.Threading.ThreadState)info.GetValue("Status", typeof(System.Threading.ThreadState)); this.param = (ThreadParam)info.GetValue("Param", typeof(ThreadParam)); this.lastPollTime = info.GetDateTime("LastPollTime"); this.lastMessage = info.GetString("LastMessage"); this.lastExceptionMessage = info.GetString("LastExceptionMessage"); }
protected virtual void doWorkP(object parms) { ThreadState = System.Threading.ThreadState.Running; m_ParamMethod(parms); ThreadState = System.Threading.ThreadState.Stopped; if (threadCallback != null) { threadCallback(ThreadId.ToString()); } }
protected virtual void doWork() { ThreadState = System.Threading.ThreadState.Running; m_SimpleMethod(); ThreadState = System.Threading.ThreadState.Stopped; if (threadCallback != null) { threadCallback(ThreadId.ToString()); } }
public System.Threading.ThreadState[] GetAllThreadStates() { System.Threading.ThreadState[] states = new System.Threading.ThreadState[this.Count]; for (int i = 0; i < this.Count; i++) { states[i] = this[i].CurrentThread.ThreadState; } return(states); }
//-------------------------------------------------------------------------------- /// <summary> /// The sit/spin thread delegate method /// </summary> private void UpdateThread() { m_threadState = System.Threading.ThreadState.Running; try { DateTime temp; DateTime now; DateTime then = new DateTime(0); TimeSpan interval = new TimeSpan(0, 0, this.m_settings.SyncMinutes, 0, 0); bool waiting = true; while (true) { if (m_threadState == System.Threading.ThreadState.Running) { temp = DateTime.Now; now = new DateTime(temp.Year, temp.Month, temp.Day, temp.Hour, temp.Minute, 0, 0); if (!waiting) { int difference = (this.m_settings.NormalizeTime) ? now.Minute % m_settings.SyncMinutes : 0; then = now.Add(interval.Subtract(new TimeSpan(0, 0, difference, 0, 0))); waiting = true; } if (now.Equal(then, m_equalityFlags) || then.Ticks == 0) { waiting = false; CheckForFiles(); } else { Thread.Sleep(1000); } } else { Thread.Sleep(1000); } } } catch (ThreadAbortException) { // we don't care if the thread aborted because we probably aborted it. } catch (Exception ex) { m_log.SendErrorToLog(ex.Message); } }
/// <summary> /// This function will initialize the neccessary class members so if initialization is /// forgotten the result does not crash the application. /// </summary> protected void init() { m_ThreadState = System.Threading.ThreadState.Unstarted; m_SeedThread = false; }
/// <summary> /// 检测日志输出 /// </summary> /// <param name="isCheckRun">是否检测运行状态,false 表示输出所有线程信息</param> public static void CheckThreadLog(bool isCheckRun = true) { LeftArray <AutoCSer.Threading.Thread> threads = AutoCSer.Threading.Thread.GetThreads(isCheckRun).getLeftArray(); AutoCSer.LogHelper.Debug("线程数量 " + threads.Length.toString()); int currentId = Thread.CurrentThread.ManagedThreadId; foreach (AutoCSer.Threading.Thread threadInfo in threads) { Thread thread = threadInfo.Handle; if (thread.ManagedThreadId != currentId) { StackTrace stack = null; Exception exception = null; System.Threading.ThreadState threadState = default(System.Threading.ThreadState); bool isSuspend = false; try { threadState = thread.ThreadState; #pragma warning disable 618 if ((threadState & (System.Threading.ThreadState.StopRequested | System.Threading.ThreadState.SuspendRequested | System.Threading.ThreadState.Stopped | System.Threading.ThreadState.AbortRequested | System.Threading.ThreadState.Aborted)) == 0) { if ((threadState & (System.Threading.ThreadState.Unstarted | System.Threading.ThreadState.WaitSleepJoin | System.Threading.ThreadState.Suspended)) == 0) { thread.Suspend(); isSuspend = true; } stack = new StackTrace(thread, true); } #pragma warning restore 618 //if (stack.FrameCount == AutoCSer.Threading.Thread.DefaultFrameCount) stack = null; } catch (ThreadStateException) { if ((threadState & System.Threading.ThreadState.WaitSleepJoin) == 0) { AutoCSer.LogHelper.Debug(threadState.ToString()); } } catch (Exception error) { exception = error; } finally { #pragma warning disable 618 if (isSuspend) { thread.Resume(); } #pragma warning restore 618 } if (exception != null) { try { AutoCSer.LogHelper.Exception(exception); } catch { } } if (stack != null) { try { AutoCSer.LogHelper.Debug(stack.ToString(), LogLevel.Debug | LogLevel.AutoCSer); } catch { } } } } }
private void ThreadEntry() { failsafeThreadState = System.Threading.ThreadState.Stopped; OnDoWork(); }
private static void printThreadState(System.Threading.ThreadState state) { Console.WriteLine("스레드 상태 : {0, -16} : {1} \n", state, (int)state); }
private void Update() { if (Application.isPlaying && !WorkScheduler.Paused) { if (this.secondaryThreadUpdating && this.thread.IsAlive) { this.mainThreadUpdating = false; } else { this.stopwatch.Stop(); WorkScheduler.CurrentTime = Time.time; this.DelayWithPreviousUpdate = Convert.ToSingle(this.stopwatch.ElapsedMilliseconds); this.mainThreadUpdating = true; if (this.ScaleWithFPS) { if (float.IsNaN(this.fps)) { this.fps = 0f; } if (float.IsNaN(this.currentQuality)) { this.currentQuality = 0f; } this.fps = Mathf.Lerp(this.fps, 1f / Time.smoothDeltaTime, 0.05f); float b = Mathf.Clamp(this.TargetFPS / this.fps, 0.75f, 5f); this.currentQuality = Mathf.Lerp(this.currentQuality, b, 0.1f); this.currentQuality = Mathf.Max(0.33f, this.currentQuality); } else { this.currentQuality = 1f; } float num = this.MaxMilliseconds * this.currentQuality; long num2 = (long)(num * (float)(Stopwatch.Frequency / 1000L)); long num3 = num2; this.stopwatch.Reset(); this.stopwatch.Start(); this.oneShotScheduler.DoWork(num3, true); this.globalScheduler.DoWork(num3 / 20L, false); this.stopwatch.Reset(); this.stopwatch.Start(); if (Scene.SceneTracker && Scene.SceneTracker.allPlayers != null) { if (LocalPlayer.Transform) { this.localPlayerPosition = LocalPlayer.Transform.position; } if (LocalPlayer.Transform && Vector3.Distance(this.previousPosition, this.localPlayerPosition) > this.GridWorldSize / 2f) { WorkScheduler.ShouldDoFullCycle = true; } if (WorkScheduler.FullCycle) { this.ProcessArea(this.previousPosition, num3, true, false); } else if (BoltNetwork.isServer) { for (int i = 0; i < Scene.SceneTracker.allPlayers.Count; i++) { this.ProcessArea(Scene.SceneTracker.allPlayers[i].transform.position, (!(Scene.SceneTracker.allPlayers[i].transform == LocalPlayer.Transform)) ? (num3 / 3L) : num3, false, false); } } else if (LocalPlayer.Transform) { this.ProcessArea(LocalPlayer.Transform.position, num3, false, false); } if (LocalPlayer.Transform) { this.previousPosition = LocalPlayer.Transform.position; } WorkScheduler.FullCycle = false; } this.stopwatch.Stop(); this.mainThreadUpdating = false; System.Threading.ThreadState threadState = this.thread.ThreadState; if (!this.thread.IsAlive) { UnityEngine.Debug.Log("Restarting thread: state=" + threadState); this.thread = null; this.OnEnable(); } this.stopwatch.Reset(); this.stopwatch.Start(); } } }
//-------------------------------------------------------------------------------- /// <summary> /// Continue a suspended service /// </summary> protected override void OnContinue() { base.OnContinue(); m_threadState = System.Threading.ThreadState.Suspended; }
public System.Threading.ThreadState[] GetAllThreadStates() { System.Threading.ThreadState[] states = new System.Threading.ThreadState[this.Count]; for(int i = 0; i < this.Count; i++) { states[i] = this[i].CurrentThread.ThreadState; } return states; }
//-------------------------------------------------------------------------------- /// <summary> /// Pauses a running service /// </summary> protected override void OnPause() { m_threadState = System.Threading.ThreadState.Running; base.OnPause(); }
/// <summary> /// Stops the time manager if not stopped already /// </summary> /// <returns>success</returns> public bool Stop() { if (m_timeThread == null) { return(false); } lock (m_lockObject) { m_running = false; if (!m_timeThread.Join(10000)) { try { if (log.IsErrorEnabled) { ThreadState state = m_timeThread.ThreadState; StackTrace trace = Util.GetThreadStack(m_timeThread); log.ErrorFormat("failed to stop the time thread \"{0}\" in 10 seconds (thread state={1}); thread stacktrace:\n", m_name, state); log.ErrorFormat(Util.FormatStackTrace(trace)); log.ErrorFormat("aborting the thread.\n"); } } finally { m_timeThread.Abort(); try { while (!m_timeThread.Join(2000)) { log.ErrorFormat("Timer Thread ({0}) can't stop after abort... maybe remaining threads going... trying again !"); try { m_timeThread.Abort(); } catch { } } } catch { } } } m_timeThread = null; Array.Clear(m_buckets, 0, m_buckets.Length); Array.Clear(m_cachedBucket, 0, m_cachedBucket.Length); #if MonitorCallbacks try { m_delayLog.Flush(); m_delayLog.Close(); } catch (Exception e) { log.Error("Closing delays log while stop() " + m_name, e); } #endif return(true); } }
private TaskState MapToState(ThreadState threadState) => threadState switch {