Created
October 10, 2017 21:04
-
-
Save elmissouri16/2e62d480a834a2b19f0f5ecb3b7b23df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace test_manual_reset_event | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
Start(); | |
if (Console.ReadLine() == "p") | |
{ | |
Pause(); | |
} | |
else if (Console.ReadLine() == "r") | |
{ | |
Resume(); | |
} | |
} | |
public static ManualResetEvent wait_handle = new ManualResetEvent(true); | |
public static void Start() | |
{ | |
Thread thread = new Thread(Work); | |
thread.Start(); | |
} | |
public static void Pause() | |
{ | |
wait_handle.Reset(); | |
} | |
public static void Resume() | |
{ | |
wait_handle.Set(); | |
} | |
public static void Work() | |
{ | |
for (int i = 0; i < 1000000; i++) | |
{ | |
wait_handle.WaitOne(); | |
Console.WriteLine(i); | |
Thread.Sleep(400); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment