/// <summary> /// This method waits for an asynchronous event message from the MF framework. /// </summary> /// <param name="eventType">The type of the event to wait for.</param> /// <param name="specificEventCheckingFunc">A specific event checking func implemented by the caller. Returns false if the event is not handled.</param> /// <param name="cancelToken">The cancellation token.</param> internal Task <MF.MediaEvent> WaitForEventAsync( MF.MediaEventTypes eventType, Func <MF.MediaEvent, bool> specificEventCheckingFunc, CancellationToken cancelToken) { TaskCompletionSource <MF.MediaEvent> eventWaitTaskResult = new TaskCompletionSource <MF.MediaEvent>(); // Define the wait action Func <MF.MediaEvent, bool> waitFunc = (givenEventData) => { // Handle cancellation if (cancelToken.IsCancellationRequested) { eventWaitTaskResult.TrySetCanceled(); return(true); } // Is this event that one we are waiting for? if (givenEventData.TypeInfo != eventType) { return(false); } // Handle result of the given event if (givenEventData.Status != SharpDX.Result.Ok) { eventWaitTaskResult.TrySetException(new SDX.SharpDXException(givenEventData.Status)); } else { // If given, then execute special event checking if (specificEventCheckingFunc != null) { if (!specificEventCheckingFunc(givenEventData)) { return(false); } } // Finish task eventWaitTaskResult.TrySetResult(givenEventData); } return(true); }; // Register waiter lock (m_asyncEventWaitersLock) { m_asyncEventWaiters.Add(waitFunc); } return(eventWaitTaskResult.Task); }
/// <summary> /// This method waits for an asynchronous event message from the MF framework. /// </summary> /// <param name="eventType">The type of the event to wait for.</param> /// <param name="cancelToken">The cancellation token.</param> internal Task <MF.MediaEvent> WaitForEventAsync( MF.MediaEventTypes eventType, CancellationToken cancelToken) { return(WaitForEventAsync(eventType, null, cancelToken)); }