public void Pause() { if (Interlocked.CompareExchange(ref m_paused, new TaskCompletionSource <bool>(), null) == null) { Paused?.Invoke(); PauseStatusChanged?.Invoke(true); } }
public void Resume() { while (true) { var tcs = m_paused; if (tcs == null) { return; } if (Interlocked.CompareExchange(ref m_paused, null, tcs) == tcs) { tcs.SetResult(true); Resumed?.Invoke(); PauseStatusChanged?.Invoke(false); break; } } }