当前位置: 首页>>代码示例>>C#>>正文


C# Thread.Suspend方法代码示例

本文整理汇总了C#中Thread.Suspend方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.Suspend方法的具体用法?C# Thread.Suspend怎么用?C# Thread.Suspend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Thread的用法示例。


在下文中一共展示了Thread.Suspend方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AbortTest12

 private void AbortTest12( ) {
 Console.WriteLine("AT12:Start Test");
 ThreadStart		ts	= new ThreadStart(this.Abortee12);
 Thread			t	= new Thread(ts);
 t.Start( );
 Delay(500);
 Console.WriteLine("AT12:suspending t1");
 t.Suspend( );
 Delay(50000);
 }	
开发者ID:ArildF,项目名称:masters,代码行数:10,代码来源:cs_abort.cs

示例2: 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();
         }
     }
 }
开发者ID:Tirasa,项目名称:ConnId,代码行数:21,代码来源:Server.cs

示例3: 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();
    }
开发者ID:Meowse,项目名称:student1,代码行数:60,代码来源:ThreadSuspending.cs

示例4: 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();
        }
开发者ID:ilya11211,项目名称:nprof,代码行数:28,代码来源:TestClass.cs


注:本文中的Thread.Suspend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。