private async Task <PPError> DeleteAsyncCore(MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <PPError>(); EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleDelete += handler; if (MessageLoop == null && messageLoop == null) { Delete(); } else { Action <PPError> action = new Action <PPError>((e) => { var result = (PPError)PPBFileRef.Delete(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 { HandleDelete -= handler; } }
/// <summary> /// Delete() deletes a file or directory. If <code>FileRef</code> refers to /// a directory, then the directory must be empty. It is an error to delete a /// file or directory that is in use. It is not valid to delete a file in /// the external file system. /// </summary> /// <returns>Error code</returns> public PPError Delete() => (PPError)PPBFileRef.Delete(this, new CompletionCallback(OnDelete));