本文整理汇总了C#中ThreadState类的典型用法代码示例。如果您正苦于以下问题:C# ThreadState类的具体用法?C# ThreadState怎么用?C# ThreadState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThreadState类属于命名空间,在下文中一共展示了ThreadState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AwaitState
/// <summary>
/// Waits for all incoming threads to be in wait()
/// methods.
/// </summary>
public static void AwaitState(ThreadState state, params ThreadClass[] threads)
{
while (true)
{
bool done = true;
foreach (ThreadClass thread in threads)
{
if (thread.State != state)
{
done = false;
break;
}
}
if (done)
{
return;
}
if (Random().NextBoolean())
{
[email protected]();
}
else
{
Thread.Sleep(1);
}
}
}
示例2: btnPause_Click
private void btnPause_Click(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
if (state == ThreadState.Running) // Press Pause Button's
{
if (Algorithm.Algorithm.GetInstance().Pause())
{
state = ThreadState.Suspended;
btnStart.Enabled = true;
btnPause.Enabled = false;
btnPause.Text = "&Pause";
btnStop.Enabled = true;
btnStart.Text = "&Resume";
if (ResultForm._setting.AutoSave_OnStopped)
{
Save(Algorithm.Algorithm.GetInstance().GetBestChromosome());
}
}
}
else if (state == ThreadState.Stopped || state == ThreadState.Aborted) // Press Sava Button's
{
Save(Algorithm.Algorithm.GetInstance().GetBestChromosome());
btnStart.Enabled = true;
btnPause.Enabled = false;
btnPause.Text = "&Pause";
btnStop.Enabled = false;
}
this.Cursor = Cursors.Default;
}
示例3: Thread
public Thread(Closure closure, int stackSize)
{
ThreadClosure = closure;
State = new ThreadState(stackSize);
State.CurrentInstruction = new InstructionPointer(closure.Func, closure.ClosedVars, 0);
State.CurrentInstruction.InstructionIndex = -1;
}
示例4: CanComplete
public override bool CanComplete(ThreadState threadState)
{
// A DelayedUnlock can be completed even if the thread does not
// own the lock, then the execution does not affect anything
// except that the instruction acts as a barrier preventing
// instruction before to be completed after the unlock
return true;
}
示例5: _1_SimplifyThreadState
public static ThreadState _1_SimplifyThreadState(ThreadState ts)
{
// Technique to convert threadstate to one of the 4 most useful values:
// Unstarted, Running, WaitSleepJoin, and Stopped
return ts & (ThreadState.Unstarted |
ThreadState.WaitSleepJoin |
ThreadState.Stopped);
}
示例6: TimedAction
private readonly ThreadState _threadState; // State of the thread
#endregion Fields
#region Constructors
/// <summary> Constructor. </summary>
/// <param name="interval"> The execution interval. </param>
/// <param name="action"> The action to execute. </param>
public TimedAction(double interval, Action action)
{
_action = action;
_threadState = new ThreadState {IsRunning = false};
_actionTimer = new Timer(interval) {Enabled = false, SynchronizingObject = null};
_actionTimer.Elapsed += OnActionTimer;
}
示例7: TimedAction
private readonly ThreadState _threadState; // State of the thread
#endregion Fields
#region Constructors
/// <summary> Constructor. </summary>
/// <param name="disposeStack">Dispose stack to add itself to</param>
/// <param name="interval"> The execution interval. </param>
/// <param name="action"> The action to execute. </param>
public TimedAction(DisposeStack disposeStack, double interval, Action action)
{
disposeStack.Push(this);
_action = action;
_threadState = new ThreadState {IsRunning = false};
_actionTimer = new Timer(interval) {Enabled = false, SynchronizingObject = null};
_actionTimer.Elapsed += OnActionTimer;
}
示例8: CanComplete
public override bool CanComplete(ThreadState threadState)
{
// TODO: (much later) support exception here
VMValue_objectinst vinst = (VMValue_objectinst)threadState.GetValue(obj);
if(vinst.HoldingLockThreadID != threadState.ThreadID)
throw new Exception("Calling pulse on a lock we don't possess");
return true;
}
示例9: ThreadTraceInfo
public ThreadTraceInfo(int id, string name, DateTime start, float cpuUsage, TimeSpan totalCpuUsageTime, ThreadState state)
{
_id = id;
_name = name;
_start = start;
_cpuUsage = cpuUsage;
_totalCpuUsageTime = totalCpuUsageTime;
_state = state;
}
示例10: ThreadSurrogated
public ThreadSurrogated(Thread thread)
{
Id = thread.ManagedThreadId;
Name = thread.Name;
Priority = thread.Priority;
State = thread.ThreadState;
IsBackground = thread.IsBackground;
IsThreadPoolThread = thread.IsThreadPoolThread;
}
示例11: Start
public void Start(Action<Exception> threadFailedHandler)
{
if (threadFailedHandler != null)
ThreadFailed += threadFailedHandler;
StartCore();
m_State = ThreadState.Starting;
m_Thread.Start();
}
示例12: SmartThread
/// <summary>
/// 创建线程
/// </summary>
/// <param name="name"></param>
/// <param name="task"></param>
/// <param name="isBackground"></param>
/// <param name="apartmentState"></param>
public SmartThread(Action task, string name = null, bool isBackground = true, ApartmentState apartmentState = ApartmentState.MTA)
{
if (task == null)
throw new ArgumentNullException("task");
InnerThread = new System.Threading.Thread(()=>task()) { Name = name, IsBackground = isBackground };
InnerThread.SetApartmentState(apartmentState);
mutex = new ResetEvent(false);
State = ThreadState.NotStarted;
}
示例13: CanComplete
// A lock action can be completed if the lock is free
// or it is currently hold by the same thread
public override bool CanComplete(ThreadState threadState)
{
// A DelayedLock can only be completed if the object instance is not locked
// or it is already locked by this thread
VMValue_objectinst vinst = (VMValue_objectinst)threadState.GetValue(obj);
if((vinst.HoldingLockThreadID == threadState.ThreadID) ||
(vinst.HoldingLockThreadID == -1))
return true;
else
return false;
}
示例14: DocumentsWriterPerThreadPool
/// <summary>
/// Creates a new <seealso cref="DocumentsWriterPerThreadPool"/> with a given maximum of <seealso cref="ThreadState"/>s.
/// </summary>
public DocumentsWriterPerThreadPool(int maxNumThreadStates)
{
if (maxNumThreadStates < 1)
{
throw new System.ArgumentException("maxNumThreadStates must be >= 1 but was: " + maxNumThreadStates);
}
ThreadStates = new ThreadState[maxNumThreadStates];
NumThreadStatesActive = 0;
for (int i = 0; i < ThreadStates.Length; i++)
{
ThreadStates[i] = new ThreadState(null);
}
}
示例15: executeScript
/// <summary>
/// Start executing the robotscript
/// </summary>
public void executeScript()
{
try
{
thread = new Thread(new ThreadStart(scriptexecutor));
thState = thread.ThreadState;
thread.Start();
}
catch (ThreadStateException)
{
return;
}
}