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


C# Thread.Suspend方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            Console.WriteLine("主线程-创建线程实例");
            //创建子线程
            Thread thread = new Thread(new ThreadStart(ThreadProc));
            Console.WriteLine("主线程-子线程状态:{0}", thread.ThreadState);
            //启动子线程
            Console.WriteLine("主线程调用start方法");
            thread.Start();
            Console.WriteLine("主线程-子线程状态{0}", thread.ThreadState);
            Thread.Sleep(5000);
            Console.WriteLine("主线程-调用suspend方法");
            thread.Suspend();
            Console.WriteLine("主线程-子线程状态{0}", thread.ThreadState);
            Thread.Sleep(1000);
            Console.WriteLine("主线程-调用resume方法");

            thread.Resume();
            Console.WriteLine("主线程-子线程状态{0}", thread.ThreadState);

            Thread.Sleep(5000);
            Console.WriteLine("主线程-调用abort方法");
            thread.Abort();
            Console.WriteLine("主线程-子线程状态{0}", thread.ThreadState);
            Console.WriteLine("主线程-调用join方法");
            Console.WriteLine("主线程-子线程状态{0}", thread.ThreadState);
            Console.Read();
        }
开发者ID:siyongshuai,项目名称:winformBasic,代码行数:28,代码来源:Program.cs

示例2: Teste_MultiThreading

        public void Teste_MultiThreading()
        {
            // Thread Corrente
            // Thread.CurrentThread.ManagedThreadId;

            ThreadStart pontoEntrada = new ThreadStart(ExecutarTeste);

            Thread _thread = new Thread(pontoEntrada);
            _thread.Name = "Thread principal...";
            _thread.Start();

            _thread.Suspend();
            _thread.Resume();
            _thread.Abort();

            try
            {

            }
            catch (ThreadAbortException)
            {

                throw;
            }
        }
开发者ID:lhlima,项目名称:CollaborationProjects,代码行数:25,代码来源:RecursosMultiThreading.cs

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

示例4: Main

        static void Main(string[] args)
        {
            //主线程不需要显示启动
            Thread.CurrentThread.Name = "主线程";
            Console.WriteLine("主线程启动");

            //创建用户线程
            Thread thread = new Thread(new ThreadStart(ThreadProc));
            //启动用户线程
            thread.Start();
            //suspend user thread
            thread.Suspend();
            Console.WriteLine("用户线程挂起");
            Console.WriteLine(thread.IsAlive);
            //suspend 5s
            Thread.Sleep(5000);
            thread.Resume();
            Console.WriteLine("用户线程恢复");

            //suspend 5s
            Thread.Sleep(5000);
            //结束用户线程
            thread.Abort();
            thread.Join();
            Console.WriteLine("用户线程结束");

            Console.Read();
        }
开发者ID:siyongshuai,项目名称:winformBasic,代码行数:28,代码来源:Program.cs

示例5: Main

 static void Main(string[] args)
 {
     ThreadStart ts = new ThreadStart(Method);
     Thread t = new Thread(ts);
     t.Start(); // Запуск потока.
     Console.WriteLine("Нажмите любую клавишу для остановки");
     Console.ReadKey();
     t.Suspend(); // Приостановка потока.
     Console.WriteLine("Поток остановлен!");
     Console.WriteLine("Нажмите любую клавишу для возобновления");
     Console.ReadKey();
     t.Resume(); // Возобновление работы.
 }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:13,代码来源:Program.cs

示例6: Main

 static void Main(string[] args)
 {
     ThreadStart ts = new ThreadStart(Method);
     Thread t = new Thread(ts);
     t.Start();
     Console.WriteLine("Press any key to stop stream");
     Console.ReadKey();
     t.Suspend();
     Console.WriteLine("Stream stoped");
     Console.WriteLine("Press any key to continue stream");
     Console.ReadKey();
     t.Resume();
 }
开发者ID:RoykoSerhiy,项目名称:visualStudio_projects,代码行数:13,代码来源:Program.cs

示例7: Main

        public static void Main(string[] args)
        {
            Console.Write("Diga o nome do arquivo de img: ");
            string nomeArq = Console.ReadLine();
            Console.Write("Diga o tamanho do embacamento: ");
            int coef = Int32.Parse(Console.ReadLine());
            Image imagem = Image.FromFile(nomeArq);
            Bitmap bitmap = new Bitmap(imagem);
            Console.Write("Quantas thread horizontais? ");
            int threadsH = Int32.Parse(Console.ReadLine());
            Console.Write("Quantas thread verticais? ");
            int threadsV = Int32.Parse(Console.ReadLine());
            totalThreads = threadsH * threadsV;

            ThreadEmb[,] threads = new ThreadEmb[threadsV, threadsH];

            int i, j;
            int qtdX = bitmap.Width / threadsH;
            int qtdY = bitmap.Height / threadsV;
            Graphics g = Graphics.FromImage(bitmap);

            for(i = 0; i < threadsV; i++)
                for (j = 0; j < threadsH; j++)
                    threads[i, j] = new ThreadEmb((Bitmap)bitmap.Clone(), coef, qtdX * j, qtdX, qtdY * i, qtdY, i, j);

            Thread t;
            ThreadStart ts;

            threadPrincipal = Thread.CurrentThread;

            for (i = 0; i < threadsV; i++)
                for (j = 0; j < threadsH; j++)
                {
                    ts = new ThreadStart(threads[i, j].Iniciar);
                    t = new Thread(ts);
                    t.Start();
                }

            //while (threadCompletas < totalThreads) { }

            threadPrincipal.Suspend();

            for (i = 0; i < threadsV; i++)
                for (j = 0; j < threadsH; j++)
                    threads[i,j].desenhaResultado(g);

            bitmap.Save("editado_" + nomeArq);
        }
开发者ID:mateusazis,项目名称:Embacador,代码行数:48,代码来源:EmbacadorMultiThread.cs

示例8: Main

        static void Main()
        {
            CharGenerator g1 = new CharGenerator();
            CharGenerator g2 = new CharGenerator();
            CharGenerator g3 = new CharGenerator();
            Thread t1 = new Thread(new ThreadStart(g1.GenerateChar));
            Thread t2 = new Thread(new ThreadStart(g2.GenerateChar));
            Thread t3 = new Thread(new ThreadStart(g3.GenerateChar));
            t1.Start();
            t2.Start();
            t3.Start();

            string input = "";

            do
            {

                Console.WriteLine("Enter \"try\" when you're ready, \"exit\" to escape");
                input = Console.ReadLine();

                if (input == "try" || input == "t")
                {
                    t1.Suspend();
                    t2.Suspend();
                    t3.Suspend();
                    if (g1.ch == g2.ch && g2.ch == g3.ch)
                    {
                        Console.WriteLine(g1.ch + " " + g2.ch + " " + g3.ch + " won");
                    }
                    else
                    {
                        Console.WriteLine(g1.ch + " " + g2.ch + " " + g3.ch + " lost");
                    }

                    t1.Resume();
                    t2.Resume();
                    t3.Resume();
                }
                Thread.Sleep(100);
            } while (input != "exit");

            g1.end = true;
            g2.end = true;
            g3.end = true;

            return;
        }
开发者ID:Rokata,项目名称:TechnicalUniversity,代码行数:47,代码来源:Synchronization.cs

示例9: GetStackTrace

 /// <summary>
 /// http://stackoverflow.com/questions/285031/how-to-get-non-current-threads-stacktrace/14935378#14935378
 /// </summary>
 /// <param name="targetThread"></param>
 /// <returns></returns>
 private static StackTrace GetStackTrace(Thread targetThread)
 {
     ManualResetEventSlim fallbackThreadReady = new ManualResetEventSlim();
     ManualResetEventSlim exitedSafely = new ManualResetEventSlim();
     try
     {
         new Thread(delegate()
         {
             fallbackThreadReady.Set();
             if (!exitedSafely.Wait(200))
             {
                 try
                 {
                     targetThread.Resume();
                 }
                 catch (Exception) {/*Whatever happens, do never stop to resume the main-thread regularly until the main-thread has exited safely.*/}
             }
         }).Start();
         fallbackThreadReady.Wait();
         //From here, you have about 200ms to get the stack-trace.
         targetThread.Suspend();
         StackTrace trace = null;
         try
         {
             trace = new StackTrace(targetThread, true);
         }
         catch (ThreadStateException)
         {
             //failed to get stack trace, since the fallback-thread resumed the thread
             //possible reasons:
             //1.) This thread was just too slow
             //2.) A deadlock ocurred
             //Automatic retry seems too risky here, so just return null.
         }
         try
         {
             targetThread.Resume();
         }
         catch (ThreadStateException) {/*Thread is running again already*/}
         return trace;
     }
     finally
     {
         //Just signal the backup-thread to stop.
         exitedSafely.Set();
     }
 }
开发者ID:Elders,项目名称:Hystrix.NET,代码行数:52,代码来源:ExceptionThreadingUtility.cs

示例10: Start

        public void Start()
        {
            System.Threading.Thread work1 = new System.Threading.Thread (WorkA);
            System.Threading.Thread work2 = new System.Threading.Thread (WorkB);

            work1.Priority = ThreadPriority.Lowest;
            work2.Priority = ThreadPriority.Highest;

            work1.Start();
            work2.Start();

            work1.Suspend();
            Console.ReadLine();
            work1.Resume();

            Console.ReadLine();
        }
开发者ID:mariochavez,项目名称:Cesun-AppDistribuidas,代码行数:17,代码来源:Hilos.cs

示例11: run

 /// <summary>
 /// 报警线程
 /// </summary>
 public void run()
 {
     strSend = "正在初始化...";
     label1.Text = "正在初始化...";
     send(strSend);
     Thread.Sleep(5000);
     showBreakRecord();
     Thread t1 = new Thread(new ThreadStart(showBadRecord));
     t1.IsBackground = true;
     t1.Start();
     while (true)
     {
         //-----设置断网信息输出时间间隔-----
         Thread.Sleep(120000);
         t1.Suspend();
         showBreakRecord();
         t1.Resume();
     }
 }
开发者ID:SaintLoong,项目名称:ZiChang_PlatForm,代码行数:22,代码来源:Alarmscl2005.cs

示例12: CreateForThread

        public static ApplicationHangException CreateForThread(Thread thread)
        {
            StackTrace tt = null;
            if (!IsMono)
            {
#if !CORECLR
#pragma warning disable 0618
                try
                {
                    thread.Suspend();
                }
                catch
                {
                    return null;
                }
                try
                {
                    tt = new System.Diagnostics.StackTrace(thread, false);
                }
                catch (ThreadStateException)
                {
                }
                try
                {
                    thread.Resume();
                }
                catch (Exception)
                {
                    Thread.Sleep(3000);
                    thread.Resume();
                }
#pragma warning restore 0618
#endif
            }


            return new ApplicationHangException(
                tt, 
                thread.Name
                );
        }
开发者ID:antiufo,项目名称:Shaman.SingleThreadSynchronizationContext,代码行数:41,代码来源:ApplicationHangException.cs

示例13: GetThreadStackTrace

 public static StackTrace GetThreadStackTrace(Thread targetThread, bool needFileInfo)
 {
     StackTrace stackTrace;
     if (targetThread == Thread.CurrentThread) // current thread
     {
         stackTrace = new StackTrace(needFileInfo); // skip ... frames (reporter stack)
     }
     else // other thread
     {
         targetThread.Suspend();
         try
         {
             stackTrace = new StackTrace(targetThread, needFileInfo);
         }
         finally
         {
             targetThread.Resume();
         }
     }
     return stackTrace;
 }
开发者ID:Roviker,项目名称:Shtirlitz,代码行数:21,代码来源:ThreadsDumpReporter.cs

示例14: Main

        static void Main(string[] args)
        {
            Thread thr = new Thread(OnPrint);
            thr.Name = "Thread Two";
            thr.Start();

            Thread.Sleep(1000);

            /*Suspend thread*/
            /*When thread suspend no exception. 
            */

            thr.Suspend();

            Thread.Sleep(1000);
            if ((thr.ThreadState & ThreadState.Suspended) > 0)
                thr.Resume();

            thr.Join();
                        /* Thread don't finish. If other thread join it, they can wait and wait forever*/

            Console.WriteLine("Main thread terminating");
            Console.ReadLine(); 
        }
开发者ID:sakataa,项目名称:CompanyDocument,代码行数:24,代码来源:Program.cs

示例15: TansVehicle

        private int _instScanInterval = 200; //取指令周期,单位:毫秒

        #endregion Fields

        #region Constructors

        /// <summary>
        /// 构造函数
        /// </summary>
        public TansVehicle()
        {
            _instExeThread = new Thread(new ThreadStart(InstExeThreadProc));
            _instExeThread.Suspend(); //挂起
        }
开发者ID:BGCX262,项目名称:zwx-asrs-2012-svn-to-git,代码行数:14,代码来源:TansVehicle.cs


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