public override IAsyncResult BeginWrite (byte [] buffer, int offset, int count, AsyncCallback cback, object state) { if (!CanWrite) throw new NotSupportedException ("This stream does not support writing"); if (buffer == null) throw new ArgumentNullException ("buffer"); if (count < 0) throw new ArgumentOutOfRangeException ("count", "Must be >= 0"); if (offset < 0) throw new ArgumentOutOfRangeException ("offset", "Must be >= 0"); WriteDelegate d = new WriteDelegate (this.Write); return d.BeginInvoke (buffer, offset, count, cback, state); }
public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if (!this.CanWrite) { __Error.WriteNotSupported(); } Interlocked.Increment(ref this._asyncActiveCount); WriteDelegate delegate2 = new WriteDelegate(this.Write); if (this._asyncActiveEvent == null) { lock (this) { if (this._asyncActiveEvent == null) { this._asyncActiveEvent = new AutoResetEvent(true); } } } this._asyncActiveEvent.WaitOne(); this._writeDelegate = delegate2; return delegate2.BeginInvoke(buffer, offset, count, callback, state); }
public void Write(byte[] data, WriteCallback callback) { var writeDelegate = new WriteDelegate(Write); var asyncState = new HidAsyncState(writeDelegate, callback); writeDelegate.BeginInvoke(data, EndWrite, asyncState); }
public override IAsyncResult BeginWrite (byte [] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject) { if (handle == MonoIO.InvalidHandle) throw new ObjectDisposedException ("Stream has been closed"); if (!CanWrite) throw new NotSupportedException ("This stream does not support writing"); if (array == null) throw new ArgumentNullException ("array"); if (numBytes < 0) throw new ArgumentOutOfRangeException ("numBytes", "Must be >= 0"); if (offset < 0) throw new ArgumentOutOfRangeException ("offset", "Must be >= 0"); // reordered to avoid possible integer overflow if (numBytes > array.Length - offset) throw new ArgumentException ("array too small. numBytes/offset wrong."); if (!async) return base.BeginWrite (array, offset, numBytes, userCallback, stateObject); FileStreamAsyncResult result = new FileStreamAsyncResult (userCallback, stateObject); result.BytesRead = -1; result.Count = numBytes; result.OriginalCount = numBytes; if (buf_dirty) { MemoryStream ms = new MemoryStream (); FlushBuffer (ms); ms.Write (array, offset, numBytes); offset = 0; numBytes = (int) ms.Length; } WriteDelegate w = new WriteDelegate (WriteInternal); return w.BeginInvoke (array, offset, numBytes, userCallback, stateObject); }
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return(writeDelegate.BeginInvoke(buffer, offset, count, callback, state)); }
public override IAsyncResult BeginWrite(byte [] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject) { if (safeHandle.IsClosed) { throw new ObjectDisposedException("Stream has been closed"); } if (!CanWrite) { throw new NotSupportedException("This stream does not support writing"); } if (array == null) { throw new ArgumentNullException("array"); } if (numBytes < 0) { throw new ArgumentOutOfRangeException("numBytes", "Must be >= 0"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Must be >= 0"); } // reordered to avoid possible integer overflow if (numBytes > array.Length - offset) { throw new ArgumentException("array too small. numBytes/offset wrong."); } if (!async) { return(base.BeginWrite(array, offset, numBytes, userCallback, stateObject)); } FileStreamAsyncResult result = new FileStreamAsyncResult(userCallback, stateObject); result.BytesRead = -1; result.Count = numBytes; result.OriginalCount = numBytes; /* * if (buf_dirty) { * MemoryStream ms = new MemoryStream (); * FlushBuffer (ms); * ms.Write (array, offset, numBytes); * * // Set arguments to new compounded buffer * offset = 0; * array = ms.ToArray (); * numBytes = array.Length; * } */ WriteDelegate w = WriteInternal; return(w.BeginInvoke(array, offset, numBytes, userCallback, stateObject)); }
public virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, Object state) { if (!CanWrite) __Error.WriteNotSupported(); // Increment the count to account for this async operation BCLDebug.Assert(_asyncActiveCount >= 1, "ref counting mismatch, possible race in the code"); Interlocked.Increment(ref _asyncActiveCount); WriteDelegate d = new WriteDelegate(Write); // To avoid a race with a stream's position pointer & generating race // conditions with internal buffer indexes in our own streams that // don't natively support async IO operations when there are multiple // async requests outstanding, we will block the application's main // thread if it does a second IO request until the first one completes. //Monitor.Enter(this); if (_asyncActiveEvent == null) { lock(this) { if (_asyncActiveEvent == null) _asyncActiveEvent = new AutoResetEvent(true); } } bool r = _asyncActiveEvent.WaitOne(); BCLDebug.Assert(r, "AutoResetEvent didn't get a signal when we called WaitOne!"); BCLDebug.Assert(_readDelegate == null && _writeDelegate == null, "Expected no other readers or writers!"); // Set delegate before we call BeginInvoke, to avoid a race _writeDelegate = d; IAsyncResult asyncResult = d.BeginInvoke(buffer, offset, count, callback, state); return asyncResult; }
public override void Write(object data, HIDDevice.WriteCallback callback,int timeout) { if (!IsConnected) return; if (IsOpen == false) OpenDevice(); var writeDelegate = new WriteDelegate(Write); var asyncState = new HidAsyncState(writeDelegate, callback); writeDelegate.BeginInvoke((byte[])data,timeout, EndWrite, asyncState); }
public void Log(string level, string thread, string ip, string recorder, string _event, string message) { write.BeginInvoke(level, thread, ip, recorder, _event, message, null, null); }