当前位置: 首页>>代码示例>>C#>>正文


C# Stream.FlushAsync方法代码示例

本文整理汇总了C#中System.IO.Stream.FlushAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.FlushAsync方法的具体用法?C# Stream.FlushAsync怎么用?C# Stream.FlushAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Stream的用法示例。


在下文中一共展示了Stream.FlushAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyStreamsAsyncParallel

        public static async Task<long> CopyStreamsAsyncParallel(Stream src, Stream dst)
        {
            long numCopied = 0;
            byte[][] buffer = new byte[2][];
            buffer[0] = new byte[0x1000];
            buffer[1] = new byte[0x1000];

            var index = 0;
            int numRead = await src.ReadAsync(buffer[index], 0, buffer[index].Length);

            while (numRead > 0)
            {
                var writeAsync = dst.WriteAsync(buffer[index], 0, numRead);
                index = index ^= 1;
                var readAsync = src.ReadAsync(buffer[index], 0, buffer[index].Length);

                Task.WaitAll(writeAsync, readAsync);
                numRead = readAsync.Result;

                numCopied += numRead;
            }
            await dst.FlushAsync();
            src.Dispose();
            dst.Dispose();

            return numCopied;

        }
开发者ID:rikace,项目名称:Experiments,代码行数:28,代码来源:Comp.cs

示例2: SaveFile

 public async Task SaveFile(string name, Stream stream)
 {
     var fullPath = GetFullPath(name);
     using (var fs = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.Write))
     {
         await stream.CopyToAsync(fs).ConfigureAwait(false);
         await stream.FlushAsync().ConfigureAwait(false);
         await fs.FlushAsync().ConfigureAwait(false);
     }
 }
开发者ID:tomasjurasek,项目名称:infrastructure,代码行数:10,代码来源:FileSystemStorageFolder.cs

示例3: CopyWithProgressAsync

        public static async Task<long> CopyWithProgressAsync(this Stream source, Stream destination,
            ProgressReportDelegate progressReport = null, long sourceLength = 0, int bufferSize = 64 * 1024)
        {
            long bytesWritten = 0;
            long totalBytesToWrite = sourceLength;

            byte[] copy_buffer = new byte[bufferSize];
            int read;
            while ((read = await source.ReadAsync(copy_buffer, 0, copy_buffer.Length)) > 0)
            {
                await destination.WriteAsync(copy_buffer, 0, read);
                bytesWritten += read;

                System.Diagnostics.Debug.WriteLine("CopyWithProgress: {0} / {1}", bytesWritten, totalBytesToWrite);
                if (null != progressReport)
                {
                    int percentComplete = 0;
                    if (sourceLength > 0)
                        percentComplete = (int)((bytesWritten/(double)totalBytesToWrite) * 100);    
                    progressReport(percentComplete, bytesWritten, totalBytesToWrite);
                }
            }

            await destination.FlushAsync();

            return bytesWritten;
        }
开发者ID:Sheringkapoting,项目名称:onedrive-explorer-win,代码行数:27,代码来源:StreamExtensionMethods.cs

示例4: WriteRequest

 private static async Task WriteRequest(byte[] message, Stream tcpStream)
 {
     var lengthBigEndian = BitConverter.GetBytes(message.Length);
     Array.Reverse(lengthBigEndian);
     tcpStream.Write(lengthBigEndian, 0, lengthBigEndian.Length);
     tcpStream.Write(message, 0, message.Length);
     await tcpStream.FlushAsync();
 }
开发者ID:stoofer,项目名称:riemann-dotnet-client,代码行数:8,代码来源:RiemannTcpClient.cs

示例5: SendOverStream

 public void SendOverStream(Stream stream, Notification value)
 {
     byte[] data = ServiceManager.Serializer.Serialize(value);
     byte[] dataLength = BitConverter.GetBytes(data.Length);
     stream.Write(dataLength, 0, dataLength.Length);
     stream.Write(data, 0, data.Length);
     stream.FlushAsync();
 }
开发者ID:SearchingFrog,项目名称:warlock-demo,代码行数:8,代码来源:Networker.cs

示例6: CopyToAsync

 public static async Task CopyToAsync(this Stream source, Stream destination, IProgress<long> progress, CancellationToken cancellationToken) {
     byte[] buffer = new byte[81920];
     int bytesRead = 0;
     long bytesTotal = 0;
     while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken)) > 0) {
         await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken);
         bytesTotal += bytesRead;
         progress?.Report(bytesTotal);
     }
     await destination.FlushAsync(cancellationToken);
 }
开发者ID:Microsoft,项目名称:RTVS,代码行数:11,代码来源:StreamExtensions.cs

示例7: ZipCatrobatPackage

 public async Task ZipCatrobatPackage(Stream zipStream, string localStoragePath)
 {
     using (var storage = StorageSystem.GetStorage())
     {
         using(var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
         {
             await WriteFilesRecursiveToZip(archive, storage, localStoragePath, "");
             await zipStream.FlushAsync();
         }
     }
     //ZipFile.CreateFromDirectory(localStoragePath, zipPath, CompressionLevel.Fastest, true);
 }
开发者ID:Catrobat,项目名称:CatrobatForWindows,代码行数:12,代码来源:ZipService.cs

示例8: DownloadAsync

        public async Task DownloadAsync(Uri uri, Stream destination, CancellationToken cancelToken)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            using (Stream stream = await m_client.GetStreamAsync(uri))
            {
                await stream.CopyToAsync(destination, 4096, cancelToken);
                await destination.FlushAsync();
            }
        }
开发者ID:shashidharpalli,项目名称:Enabling-Programmable-Self-with-HealthVault,代码行数:13,代码来源:HttpStreamer.cs

示例9: ToStreamMaxJPEGAsync

 public async static Task ToStreamMaxJPEGAsync(this Image iImage,
     Stream iStream)
 {
     using (EncoderParameters pEPsParams = new EncoderParameters(1))
     {
         EncoderParameter pEPrParam = new EncoderParameter(Encoder.Quality, 100L);
         pEPsParams.Param[0] = pEPrParam;
         using (Bitmap pBmpCopy = new Bitmap(iImage))
         {
             pBmpCopy.Save(iStream, GetEncoder(ImageFormat.Jpeg), pEPsParams);
         }
         await iStream.FlushAsync();
     }
 }
开发者ID:devoctomy,项目名称:knitup,代码行数:14,代码来源:ImageExtensions.cs

示例10: ConnectAsync

        public async Task ConnectAsync()
        {
            _tcpClient.NoDelay = true;
            await _tcpClient.ConnectAsync(_host, _port);

            _stream = _tcpClient.GetStream();
            await _stream.WriteAsync(TcpConstants.MagicCookie, 0, TcpConstants.MagicCookie.Length);
            await _stream.FlushAsync();

            ModData = await _stream.ReadObjectAsync<ModData>();

            _isConnected = true;
            var spawnedTask = Task.Run(() => RunChannel());
        }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:14,代码来源:TcpChannel.cs

示例11: SendHeaders

        private async Task SendHeaders(Uri url)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("GET / HTTP/1.1");
            sb.AppendLine("Connection: keep-alive");
            sb.AppendLine("Host: " + url.Host);
            sb.AppendLine("icy-metadata: 0");
            sb.AppendLine();

            outStream = underlayingSocket.OutputStream.AsStreamForWrite();

            var bytes = System.Text.UTF8Encoding.UTF8.GetBytes(sb.ToString());

            await outStream.WriteAsync(bytes, 0, bytes.Length);
            await outStream.FlushAsync();
        }
开发者ID:Amrykid,项目名称:Hanasu,代码行数:16,代码来源:ShoutcastStream.cs

示例12: WriteAsync

        /// <summary>
        /// Writes Packet to a stream Asynchronously
        /// </summary>
        /// <param name="stream">The stream to write to</param>
        /// <param name="flush">Flush the streams buffer</param>
        /// <param name="token">Cancellation token</param>
        /// <remarks>Known to freeze randomly so using the synchronously version is currently reccomended</remarks>
        public async Task WriteAsync(Stream stream, bool flush = true, CancellationToken token = default(CancellationToken))
        {
            if (!stream.CanWrite)
                throw new XpressNetProtocolViolationException("Unable to write to stream");

            var buffer = new List<byte>();

            buffer.Add(HeaderByte);

            buffer.AddRange(Payload);

            buffer.Add(GetXoredByte());

            await stream.WriteAsync(buffer.ToArray(), 0, buffer.Count, token);

            if (flush)
            {
                await stream.FlushAsync(token);
                LogPacketWrite();
            }
        }
开发者ID:networkfusion,项目名称:XpressNetSharp,代码行数:28,代码来源:Packet.cs

示例13: WriteToStream

        public async Task WriteToStream(Stream stream)
        {
            var bodyArray = Encoding.UTF8.GetBytes(Content);
            var contentStream = new MemoryStream(bodyArray);

            var headerBuilder = new StringBuilder();
            headerBuilder.AppendLine($"HTTP/1.1 {(int)StatusCode} {StatusCode}");
            headerBuilder.AppendLine("Server: catnap-srv/1.0.0");

            foreach (var header in Headers)
            {
                headerBuilder.AppendLine($"{header.Key}: {header.Value}");
            }

            headerBuilder.AppendLine($"Content-Length: {contentStream.Length}");
            headerBuilder.AppendLine("Connection: close");
            headerBuilder.AppendLine();

            var headerArray = Encoding.UTF8.GetBytes(headerBuilder.ToString());
            await stream.WriteAsync(headerArray, 0, headerArray.Length);
            await contentStream.CopyToAsync(stream);
            await stream.FlushAsync();
        }
开发者ID:wleev,项目名称:Catnap.Server,代码行数:23,代码来源:HttpResponse.cs

示例14: SaveBinary

        public async Task SaveBinary(string fName, Stream stream)
        {
            try
            {
                IFolder rootFolder = FileSystem.Current.LocalStorage;//;
                IFolder folder = await rootFolder.CreateFolderAsync("Settings", CreationCollisionOption.OpenIfExists, CancellationToken.None);
                IFile file = await folder.CreateFileAsync(fName, CreationCollisionOption.ReplaceExisting, CancellationToken.None);
                var t = file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite, CancellationToken.None);
                using (Stream s = await t)
                {
                    await stream.CopyToAsync(s);
                    await stream.FlushAsync();
                    s.Dispose();
                    stream.Dispose();
                }

                //stream.Dispose ();
                //s.Dispose ();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
开发者ID:pmace,项目名称:TheWall,代码行数:24,代码来源:Settings.cs

示例15: WriteAsync

        private static async Task WriteAsync(AdminProject project, Stream stream, CancellationToken cancellationToken)
        {
            var stringWriter = new StringWriter();
            await stringWriter.WriteLineAsync(string.Format("{0},{1},{2},{3},{4},{5},{6}",
                project.Id.ToCsvValue(),
                project.Name.ToCsvValue(),
                project.Created.ToCsvValue(),
                project.UserId.ToCsvValue(),
                project.UserName.ToCsvValue(),
                project.ProductType.ToCsvValue(),
                project.Product.ToCsvValue()));

            byte[] bytes = Encoding.UTF8.GetBytes(stringWriter.ToString());

            await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
            await stream.FlushAsync(cancellationToken);
        }
开发者ID:GusLab,项目名称:video-portal,代码行数:17,代码来源:ProjectForAdminCsvFormatter.cs


注:本文中的System.IO.Stream.FlushAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。