TheBulgarianWolf

More Threads

Nov 23rd, 2020
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace MoreThreads
  5. {
  6.     class Program
  7.     {
  8.         static bool isRunning = false;
  9.         static string ThreadResult;
  10.         static void ThreadWorker(object data)
  11.         {
  12.             for (int i = 0; i < (int)data; i++)
  13.             {
  14.                 Thread.Sleep(2000);
  15.             }
  16.             ThreadResult = "42";
  17.             isRunning = false;
  18.         }
  19.         static void Main(string[] args)
  20.         {
  21.             Thread t1 = new Thread(start: ThreadWorker);
  22.             isRunning = true;
  23.             Console.Write("Progress: ");
  24.  
  25.             t1.Start(5);
  26.  
  27.             while (isRunning)
  28.             {
  29.                 Console.Write(".");
  30.                 Thread.Sleep(300);
  31.             }
  32.             Console.WriteLine();
  33.             Console.WriteLine("Thread result: " + ThreadResult);
  34.  
  35.             Console.WriteLine("Press ENTER to quit.");
  36.             Console.ReadLine();
  37.  
  38.         }
  39.     }
  40. }
  41.  
Add Comment
Please, Sign In to add comment