private async Task <PPError> FlushAsyncCore(MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <PPError>(); EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleFlush += handler; if (MessageLoop == null && messageLoop == null) { Flush(); } else { Action <PPError> action = new Action <PPError>((e) => { var result = (PPError)PPBFileIO.Flush(this, new BlockUntilComplete() ); tcs.TrySetResult(result); } ); InvokeHelper(action, messageLoop); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(PPError.Aborted); } finally { HandleFlush -= handler; } }
/// <summary> /// Flush() flushes changes to disk. This call can be very expensive! /// </summary> /// <returns>Error code.</returns> public PPError Flush() => (PPError)PPBFileIO.Flush(this, new CompletionCallback(OnFlush));