Skip to content

Instantly share code, notes, and snippets.

@elmissouri16
Created October 10, 2017 21:04
Show Gist options
  • Save elmissouri16/2e62d480a834a2b19f0f5ecb3b7b23df to your computer and use it in GitHub Desktop.
Save elmissouri16/2e62d480a834a2b19f0f5ecb3b7b23df to your computer and use it in GitHub Desktop.
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