Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace MultiThreadingProblem
- {
- class Program
- {
- private static string outputText = "";
- private static Boolean stopThread = false;
- static void DisplayThread1()
- {
- while (stopThread != true)
- {
- Console.WriteLine("\nDisplay Thread 1");
- outputText = "Saya Thread 1";
- Thread.Sleep(1000);
- Console.WriteLine("Thread 1 output --> {0}", outputText);
- }
- }
- static void DisplayThread2()
- {
- while (stopThread != true)
- {
- Console.WriteLine("\nDisplay Thread 2");
- outputText = "Saya Thread 2";
- Thread.Sleep(1000);
- Console.WriteLine("Thread 2 output --> {0}", outputText);
- }
- }
- static void Main(string[] args)
- {
- Thread thread1 = new Thread(DisplayThread1);
- Thread thread2 = new Thread(DisplayThread2);
- // start them
- thread1.Start();
- thread2.Start();
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment