Advertisement
mvassilev

Untitled

Feb 25th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. public class Example {
  2.     public static void Main() {
  3.         var th = new Thread(ExecuteInForeground);
  4.         th.Start();
  5.         Thread.Sleep(1000);
  6.         Console.WriteLine("Main thread ({0}) exiting...",
  7.                           Thread.CurrentThread.ManagedThreadId);
  8.     }
  9.     private static void ExecuteInForeground() {
  10.         DateTime start = DateTime.Now;
  11.         var sw = Stopwatch.StartNew();
  12.         Console.WriteLine("Thread {0}: {1}, Priority {2}",
  13.                           Thread.CurrentThread.ManagedThreadId,
  14.                           Thread.CurrentThread.ThreadState,
  15.                           Thread.CurrentThread.Priority);
  16.         do {
  17.             Console.WriteLine("Thread {0}: Elapsed {1:N2} seconds",
  18.                               Thread.CurrentThread.ManagedThreadId,
  19.                               sw.ElapsedMilliseconds / 1000.0);
  20.             Thread.Sleep(500);
  21.         } while (sw.ElapsedMilliseconds <= 5000);
  22.         sw.Stop();
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement