private async Task <PPError> SetLengthAsyncCore(long length, MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <PPError>(); EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleSetLength += handler; if (MessageLoop == null && messageLoop == null) { SetLength(length); } else { Action <PPError> action = new Action <PPError>((e) => { var result = (PPError)PPBFileIO.SetLength(this, length, 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 { HandleSetLength -= handler; } }
/// <summary> /// SetLength() sets the length of the file. If the file size is extended, /// then the extended area of the file is zero-filled. The FileIO object must /// have been opened with write access. /// </summary> /// <param name="length">The length of the file to be set.</param> /// <returns></returns> public PPError SetLength(long length) => (PPError)PPBFileIO.SetLength(this, length, new CompletionCallback(OnSetLength));