public DispatcherState([NotNull] IDispatcherService dispatcher) { if (dispatcher == null) { throw new ArgumentNullException(nameof(dispatcher)); } if (dispatcher.CheckAccess()) { throw new InvalidOperationException("A dispatcher lock must be created from a different thread that the dispatchers it should lock"); } Dispatcher = dispatcher; Locked = new TaskCompletionSource <int>(); Unlocked = new TaskCompletionSource <int>(); }