Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace AutoIt
- {
- class ThreadManager
- {
- private static Thread threadOneThread = new Thread(threadOne);
- private static int processIdthreadOne = 0;
- private static Thread threadTwoThread = new Thread(threadTwo);
- private static int processIdthreadTwo = 0;
- private static void threadOne()
- {
- while (true)
- {
- Sounds.Done();
- Thread.Sleep(2000);
- }
- }
- private static void threadTwo()
- {
- Thread.Sleep(1000);
- while (true)
- {
- Sounds.Break();
- Thread.Sleep(2000);
- }
- }
- public static void StartStop()
- {
- Operations(threadOneThread, processIdthreadOne, "threadOne");
- Operations(threadTwoThread, processIdthreadTwo, "threadTwo");
- }
- private static void Operations(Thread thread, int processId, string processName)
- {
- if (thread == null)
- {
- thread.Start();
- Console.WriteLine("Process " + processName + ": " + thread.ManagedThreadId);
- processId = thread.ManagedThreadId;
- }
- else if (!thread.IsAlive)
- {
- thread.Start();
- Console.WriteLine("Process " + processName + ": " + thread.ManagedThreadId);
- }
- else
- {
- Console.WriteLine("Process " + processName + "(" + thread.ManagedThreadId + ") to close.");
- thread.Interrupt();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement