Advertisement
Guest User

Test

a guest
Aug 14th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace AutoIt
  5. {
  6.     class ThreadManager
  7.     {
  8.         private static Thread threadOneThread = new Thread(threadOne);
  9.         private static int processIdthreadOne = 0;
  10.         private static Thread threadTwoThread = new Thread(threadTwo);
  11.         private static int processIdthreadTwo = 0;
  12.  
  13.         private static void threadOne()
  14.         {
  15.             while (true)
  16.             {
  17.                 Sounds.Done();
  18.                 Thread.Sleep(2000);
  19.             }
  20.         }
  21.  
  22.         private static void threadTwo()
  23.         {
  24.             Thread.Sleep(1000);
  25.             while (true)
  26.             {
  27.                 Sounds.Break();
  28.                 Thread.Sleep(2000);
  29.             }
  30.         }
  31.  
  32.         public static void StartStop()
  33.         {
  34.             Operations(threadOneThread, processIdthreadOne, "threadOne");
  35.             Operations(threadTwoThread, processIdthreadTwo, "threadTwo");
  36.         }
  37.  
  38.         private static void Operations(Thread thread, int processId, string processName)
  39.         {
  40.             if (thread == null)
  41.             {
  42.                 thread.Start();
  43.                 Console.WriteLine("Process " + processName + ": " + thread.ManagedThreadId);
  44.                 processId = thread.ManagedThreadId;
  45.             }
  46.             else if (!thread.IsAlive)
  47.             {
  48.                 thread.Start();
  49.                 Console.WriteLine("Process " + processName + ": " + thread.ManagedThreadId);
  50.             }
  51.             else
  52.             {
  53.                 Console.WriteLine("Process " + processName + "(" + thread.ManagedThreadId + ") to close.");
  54.                 thread.Interrupt();
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement