Exemplo n.º 1
0
        public void Write(Stream stream)
        {
            StateObject state = new StateObject();

            state.Stream     = _outStream;
            state.SyncObject = _syncObject;

            byte[] buf       = new byte[_BDataLenght];
            int    bytesRead = stream.Read(buf, 0, buf.Length);

            while (bytesRead > 0)
            {
                if (_reverse)
                {
                    ReverseBytes(buf, 0, bytesRead);
                }
                IAsyncResult result = _outStream.BeginWrite(buf, 0, bytesRead, EndWriteAsyncCallback,
                                                            state);
                // if timeout or excheption is thrown it is may be better to break the loop.
                if (_syncObject.WaitOne(WriteTimeout) && state.Exception == null)
                {
                    bytesRead = stream.Read(buf, 0, buf.Length);
                }
                else
                {
                    break;
                }
            }
        }