WriteAsync with DataReader 如何停止读取

本文关键字:何停止 读取 DataReader with WriteAsync | 更新日期: 2023-09-27 18:33:43

我必须将mp4(Windows Phone 8.1 App C#)上传到ftp,它实际上适用于以下代码...但即使经过几天的尝试错误,我只是不知道如何为这段时间的结束写一个条件。我可以获取文件的大小,但不知道如何检查写入的字节?请帮助我

    using (var stream2 = await ftpClient.OpenWriteAsync(PathToSet + FileName + ".mp4"))
    {              
        using (var readStream = await videofile.OpenReadAsync())
        {
            IBuffer buffer = await FileIO.ReadBufferAsync(videofile);
            DataReader reader = DataReader.FromBuffer(buffer);
            byte[] fileContent = new byte[reader.UnconsumedBufferLength];                    
            //int FileSize = Convert.ToInt32(reader.UnconsumedBufferLength);
            while (true)
            {
                fileContent = new byte[reader.UnconsumedBufferLength];
                reader.ReadBytes(fileContent);
                await stream2.WriteAsync(fileContent.AsBuffer());
                if(???) break;
            }
            await stream2.FlushAsync();
        }
    }

WriteAsync with DataReader 如何停止读取

检查UnconsumedBufferLength是否为零。