本文整理汇总了C#中this.BeginWrite方法的典型用法代码示例。如果您正苦于以下问题:C# this.BeginWrite方法的具体用法?C# this.BeginWrite怎么用?C# this.BeginWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.BeginWrite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteAsync
public static IObservable<Unit> WriteAsync(this Stream This, byte[] data, int start, int length)
{
var ret = new AsyncSubject<Unit>();
try
{
This.BeginWrite(data, start, length, result =>
{
try
{
This.EndWrite(result);
ret.OnNext(Unit.Default);
ret.OnCompleted();
}
catch (Exception ex)
{
ret.OnError(ex);
}
}, null);
}
catch (Exception ex)
{
ret.OnError(ex);
}
return ret;
}
示例2: WriteAsync
public static Task WriteAsync(this Stream stream, byte[] buffer, int offset, int count)
{
var tcs = new TaskCompletionSource<object>();
var sr = stream.BeginWrite(buffer, offset, count, ar =>
{
if (ar.CompletedSynchronously)
{
return;
}
try
{
stream.EndWrite(ar);
tcs.SetResult(null);
}
catch (Exception ex)
{
tcs.SetException(ex);
}
}, null);
if (sr.CompletedSynchronously)
{
try
{
stream.EndWrite(sr);
tcs.SetResult(null);
}
catch (Exception ex)
{
tcs.SetException(ex);
}
}
return tcs.Task;
}
示例3: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// sqlfilestream.BeginWrite(buffer, callback);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this SqlFileStream sqlfilestream, Byte[] buffer, AsyncCallback callback)
{
if(sqlfilestream == null) throw new ArgumentNullException("sqlfilestream");
if(buffer == null) throw new ArgumentNullException("buffer");
return sqlfilestream.BeginWrite(buffer, 0, buffer.Length, callback);
}
示例4: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// networkstream.BeginWrite(buffer, callback);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this NetworkStream networkstream, Byte[] buffer, AsyncCallback callback)
{
if(networkstream == null) throw new ArgumentNullException("networkstream");
if(buffer == null) throw new ArgumentNullException("buffer");
return networkstream.BeginWrite(buffer, 0, buffer.Length, callback);
}
示例5: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// deflatestream.BeginWrite(array, asyncCallback);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this DeflateStream deflatestream, Byte[] array, AsyncCallback asyncCallback)
{
if(deflatestream == null) throw new ArgumentNullException("deflatestream");
if(array == null) throw new ArgumentNullException("array");
return deflatestream.BeginWrite(array, 0, array.Length, asyncCallback);
}
示例6: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// isolatedstoragefilestream.BeginWrite(buffer, userCallback);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this IsolatedStorageFileStream isolatedstoragefilestream, Byte[] buffer, AsyncCallback userCallback)
{
if(isolatedstoragefilestream == null) throw new ArgumentNullException("isolatedstoragefilestream");
if(buffer == null) throw new ArgumentNullException("buffer");
return isolatedstoragefilestream.BeginWrite(buffer, 0, buffer.Length, userCallback);
}
示例7: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// pipestream.BeginWrite(buffer, callback);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this AnonymousPipeClientStream pipestream, Byte[] buffer, AsyncCallback callback)
{
if(pipestream == null) throw new ArgumentNullException("pipestream");
if(buffer == null) throw new ArgumentNullException("buffer");
return pipestream.BeginWrite(buffer, 0, buffer.Length, callback);
}
示例8: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// stream.BeginWrite(buffer, callback, state);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this Stream stream, Byte[] buffer, AsyncCallback callback, Object state)
{
if(stream == null) throw new ArgumentNullException("stream");
if(buffer == null) throw new ArgumentNullException("buffer");
return stream.BeginWrite(buffer, 0, buffer.Length, callback, state);
}
示例9: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// gzipstream.BeginWrite(array, asyncCallback);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this GZipStream gzipstream, Byte[] array, AsyncCallback asyncCallback)
{
if(gzipstream == null) throw new ArgumentNullException("gzipstream");
if(array == null) throw new ArgumentNullException("array");
return gzipstream.BeginWrite(array, 0, array.Length, asyncCallback);
}
示例10: WriteAsync
/// <summary>
/// <paramref name="buffer"/> 내용을 지정된 스트림에 비동기 방식으로 씁니다.
/// </summary>
public static Task WriteAsync(this Stream stream, byte[] buffer, int offset, int count) {
if(IsDebugEnabled)
log.Debug("버퍼의 내용을 비동기 방식으로 스트림에 씁니다... offset=[{0}], count=[{1}]", offset, count);
// Silverlight용 TPL에서는 지원하지 3개 이상의 인자를 지원하지 않는다.
var ar = stream.BeginWrite(buffer, offset, count, null, null);
return Task.Factory.StartNew(() => stream.EndWrite(ar));
}
示例11: BeginWrite
/// <summary>
/// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
/// <example>
/// filestream.BeginWrite(array, userCallback);
/// </example>
/// </summary>
public static IAsyncResult BeginWrite(this FileStream filestream, Byte[] array, AsyncCallback userCallback)
{
if(filestream == null) throw new ArgumentNullException("filestream");
if(array == null) throw new ArgumentNullException("array");
return filestream.BeginWrite(array, 0, array.Length, userCallback);
}
示例12: BeginWrite
/// <include file='../_Doc/mscorlib.xml' path='doc/members/member[@name="M:System.IO.Stream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object)"]/*' />
/// <param name="stream">Stream on which to begin writing.</param>
public static IAsyncResult BeginWrite(this Stream stream, byte[] buffer, int offset, int count,
AsyncCallback callback, object state)
{
#if DOTNET || WINDOWS_PHONE
return stream.BeginWrite(buffer, offset, count, callback, state);
#else
return
new TaskFactory().StartNew(asyncState => stream.Write(buffer, offset, count), state)
.ContinueWith(task => callback(task));
#endif
}
示例13: NioWrite
public static IYield NioWrite(this Stream stream, byte[] buffer, int offset, int count)
{
var waitEvent = new WaitEvent();
stream.BeginWrite(buffer, offset, count, ar =>
{
stream.EndWrite(ar);
((WaitEvent) ar.AsyncState).Set();
}, waitEvent);
return Microthread.Wait(waitEvent);
}
示例14: Write
public static void Write(this Stream stream, byte[] buffer, int offset, int size, Action continuation)
{
var daemon = Daemons.Current;
stream.BeginWrite(buffer, offset, size,
asyncResult =>
{
stream.EndWrite(asyncResult);
((IDaemon)asyncResult.AsyncState).Schedule(continuation);
}, daemon);
}
示例15: WriteAsync
public static Task WriteAsync(this Stream stream, byte[] buffer)
{
try
{
return Task.Factory.FromAsync((cb, state) => stream.BeginWrite(buffer, 0, buffer.Length, cb, state), ar => stream.EndWrite(ar), null);
}
catch (System.Exception ex)
{
return TaskAsyncHelper.FromError(ex);
}
}