/// <summary> /// Adds new message to the queue. This method is thread-safe. /// </summary> /// <param name="writingDelegate">Custom delegate to write using message's stream.</param> /// <param name="parameter">Delegate parameter object.</param> /// <param name="length"> /// Specifies how much memory will be allocated for new message. /// Delegate will receive a stream with capacity limited by this parameter, but it is not forced to use all allocated space. /// </param> /// <param name="timeout">Operation timeout.</param> /// <returns> /// ChannelStateOperationResult with ChannelState and OperationStatus.Completed, OperationStatus.Timeout, OperationStatus.Cancelled, /// OperationStatus.DelegateFailed, OperationStatus.RequestedLengthIsGreaterThanLogicalAddressSpace, /// OperationStatus.RequestedLengthIsGreaterThanVirtualAddressSpace, OperationStatus.OutOfSpace or any OperationStatus returned by writingDelegate /// </returns> public IAsyncOperation <ChannelStateOperationResult> WriteAsync(AsynchronousWritingDelegateWithParameterAndResult writingDelegate, object parameter, long length, TimeSpan timeout) { return(AsyncInfo.Run(async cancellationToken => { return new ChannelStateOperationResult(await _internal.WriteAsync(DelegateHelper.Wrap(writingDelegate), parameter, length, cancellationToken, timeout)); })); }
public static Func <MemoryMappedViewStream, object, CancellationToken, Task <Internal.OperationStatus> > Wrap(AsynchronousWritingDelegateWithParameterAndResult externalDelegate) { return(async(MemoryMappedViewStream stream, object parameter, CancellationToken cancellationToken) => { if (externalDelegate == null) { return Internal.OperationStatus.Completed; } var result = await externalDelegate.Invoke(stream.AsRandomAccessStream(), parameter).AsTask(cancellationToken); return (Internal.OperationStatus)result; }); }