本文整理汇总了C#中Thread.Resume方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.Resume方法的具体用法?C# Thread.Resume怎么用?C# Thread.Resume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread.Resume方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStackTrace
private static StackTrace GetStackTrace(Thread thread)
{
bool suspended = false;
try
{
thread.Suspend();
suspended = true;
return new StackTrace(thread, true);
}
catch (ThreadStateException)
{
return null; //we missed this one
}
finally
{
if (suspended)
{
thread.Resume();
}
}
}
示例2: Main
static void Main()
{
// Get the current thread and set its name.
Thread.CurrentThread.Name = "Main Thread";
// Create an instance of the ThreadedClass.
ThreadedClass tc1 = new ThreadedClass("Thread1");
// Set the ThreadedClass's boolean internal suspend call to true.
tc1.InternalSuspendCall = true;
// Create the thread giving it the delegate with the
// method that should be called when the thread starts.
Console.WriteLine ("Main - Creating thread t1.");
Thread t1 = new Thread(tc1.ThreadMethod);
t1.Name = "T1 Worker Thread";
// Start the thread
t1.Start();
Console.WriteLine ("Main - t1 thread started.");
// Sleep for a few seconds.
Console.WriteLine("Main - Sleeping for 5 seconds.");
Thread.Sleep (5000);
// Start another thread
ThreadedClass tc2 = new ThreadedClass("Thread2");
tc2.InternalSuspendCall = false;
Thread t2 = new Thread(tc2.ThreadMethod);
t2.Name = "T2 Worker Thread";
t2.Start();
Console.WriteLine ("Main - t2 thread started.");
// Resume the first thread.
Console.WriteLine ("Main - Resuming t1 from Suspend() call.");
t1.Resume();
// Pause the second thread.
Console.WriteLine ("Main - Calling Suspend() on t2."); // *** For some reason, I occasionally see this program hang here when not debugging.
t2.Suspend(); // This may throw an exception if t2 is not running.
Console.WriteLine ("Main - Thread t2 is now suspended.");
// Wait a moment.
Console.WriteLine("Main - Sleeping for 5 seconds.");
Thread.Sleep(5000);
// Resume the second thread.
Console.WriteLine ("Main - Resuming t2 from Suspend() call.");
t2.Resume();
// Wait a moment.
Console.WriteLine("Main - Sleeping for 5 seconds.");
Thread.Sleep(5000);
// Pause the program. Usually, this message will appear
// before the message from the threaded method appears.
Console.Write ("Main - Press <ENTER> to end: ");
Console.ReadLine();
}
示例3: Run
public void Run()
{
Thread tA = new Thread( new ThreadStart( ThreadA ) );
Thread tB = new Thread( new ThreadStart( ThreadB ) );
Thread.CurrentThread.Name = "Main thread";
tA.Name = "Thread A";
tB.Name = "Thread B";
tA.Start();
tB.Start();
System.Console.WriteLine( "Suspending thread A" );
Thread.Sleep( 100 );
tA.Suspend();
Thread.Sleep( 2500 );
System.Console.WriteLine( "Suspending thread B" );
tB.Suspend();
Thread.Sleep( 2500 );
System.Console.WriteLine( "Running GC..." );
GC.Collect();
System.Console.WriteLine( "Suspending main thread" );
Thread.Sleep( 2500 );
tA.Resume();
_mreA.Set();
Thread.Sleep( 2500 );
tB.Resume();
_mreB.Set();
}
示例4: ReceiveThreadStart
public static void ReceiveThreadStart()
{
Status="Start listening";
if ( client!= null) client.Close();
receiveThread = new Thread(new ThreadStart(ReceiveString));
receiveThread.IsBackground = true;
if(receiveThread.IsAlive)receiveThread.Resume();
else receiveThread.Start();
}