Example #1
0
 private void AsyncReadCallback(IAsyncResult asyncResult)
 {
     this.CurrentAsyncState = (AsyncState)asyncResult.AsyncState;
     try
     {
         int readCn = this.CurrentAsyncState.FS.EndRead(asyncResult);
         //判断是否读到内容
         if (readCn > 0)
         {
             this.CurrentAsyncState.currentFrag.bytesLength = readCn;
             var newbuffer = this.CurrentAsyncState.currentFrag.bytes.Take(readCn).ToArray();
             this.CurrentAsyncState.currentFrag.bytes = newbuffer;
             //输出读取内容值
             this.onReadFrag?.Invoke(this, this);
         }
         //
         if (readCn < Params.flagSize)
         {
             this.onEndReadFrag?.Invoke(this, this);
             this.CurrentAsyncState.FS.Close();
             this.CurrentAsyncState.FS.Dispose();
         }
     }
     catch (Exception ex)
     {
         this.onReadFragError?.Invoke(this, this);
     }
 }
Example #2
0
        public bool SelectFileToFragSend()
        {
            var fraginfo = ChooseFileAndPath.selectFile();

            if (fraginfo == null)
            {
                return(false);
            }
            var fileinfo = File.OpenRead(fraginfo.filePath);
            var frag     = new FileFrag
            {
                currentFragIndex = 0,
                fileGuid         = fraginfo.fileGuid,
                bytes            = new byte[Params.flagSize]
            };

            //构造BeginRead需要传递的状态
            this.CurrentAsyncState = new AsyncState {
                FS = fileinfo, currentFrag = frag, fileFragInfo = fraginfo
            };
            return(true);
        }