当前位置: 首页 > news >正文

泉州网站建设策划网站开发 公司简介

泉州网站建设策划,网站开发 公司简介,聊城做网站的公司渠道,做网站怎么切片异步操作使您能在不阻塞主线程的情况下执行占用大量资源的 I/O 操作。 在 Windows 8.x 应用商店应用或桌面应用中一个耗时的流操作可能阻塞 UI 线程并让应用看起来好像不工作时#xff0c;这种性能的考虑就显得尤为重要了。 从 .NET Framework 4.5 开始#xff0c;I/O 类型包…异步操作使您能在不阻塞主线程的情况下执行占用大量资源的 I/O 操作。 在 Windows 8.x 应用商店应用或桌面应用中一个耗时的流操作可能阻塞 UI 线程并让应用看起来好像不工作时这种性能的考虑就显得尤为重要了。 从 .NET Framework 4.5 开始I/O 类型包括了异步方法以简化异步操作。 异步方法在其名称中包括 Async 例如 ReadAsync、 WriteAsync、 CopyToAsync、 FlushAsync、 ReadLineAsync和 ReadToEndAsync。 这些异步方法基于流类例如 Stream、 FileStream和 MemoryStream和用来向流中读出或写入数据的类例如 TextReader 和 TextWriter实现。 在 .NET Framework 4 和更早的版本中你必须使用 BeginRead 和 EndRead 等方法来实现异步 I/O 操作。 这些方法仍然在当前 .NET 版本中可用从而支持传统的代码但是异步方法能帮助你更轻松地实现异步 I/O 操作。 C# 和 Visual Basic 分别具有两个用于异步编程的关键字 Async (Visual Basic) 或 async (C#) 修饰符您可以用来标记包含异步操作的方法。 Await (Visual Basic) 或 await (C#) 运算符可以应用到异步方法的结果中。 如下面的示例所示若要实现异步 I/O 操作请把这些关键字和异步方法结合使用。  下面的示例演示如何使用两个 FileStream 对象把文件从一个目录异步复制到另一个目录。 需要注意 Click 控件的 Button 事件处理程序具有 async 修饰符标记因为它调用异步方法。 using System; using System.Threading.Tasks; using System.Windows; using System.IO;namespace WpfApplication {public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private async void Button_Click(object sender, RoutedEventArgs e){string startDirectory c:\Users\exampleuser\start;string endDirectory c:\Users\exampleuser\end;foreach (string filename in Directory.EnumerateFiles(startDirectory)){using (FileStream sourceStream File.Open(filename, FileMode.Open)){using (FileStream destinationStream File.Create(Path.Combine(endDirectory, Path.GetFileName(filename)))){await sourceStream.CopyToAsync(destinationStream);}}}}} }下一个例子类似于前面的例子但是使用 StreamReader 和 StreamWriter 对象以异步方式读取和写入文本文件的内容。 private async void Button_Click(object sender, RoutedEventArgs e) {string UserDirectory c:\Users\exampleuser\;using (StreamReader SourceReader File.OpenText(UserDirectory BigFile.txt)){using (StreamWriter DestinationWriter File.CreateText(UserDirectory CopiedFile.txt)){await CopyFilesAsync(SourceReader, DestinationWriter);}} }public async Task CopyFilesAsync(StreamReader Source, StreamWriter Destination) {char[] buffer new char[0x1000];int numRead;while ((numRead await Source.ReadAsync(buffer, 0, buffer.Length)) ! 0){await Destination.WriteAsync(buffer, 0, numRead);} }下一个示例演示用于在 Windows 8.x 应用商店应用中以 Stream 的形式打开文件的代码隐藏文件和 XAML 文件并且通过使用 StreamReader 类的实例来读取其内容。 它使用异步方法以流的形式打开文件并读取其内容。 using System; using System.IO; using System.Text; using Windows.Storage.Pickers; using Windows.Storage; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls;namespace ExampleApplication {public sealed partial class BlankPage : Page{public BlankPage(){this.InitializeComponent();}private async void Button_Click_1(object sender, RoutedEventArgs e){StringBuilder contents new StringBuilder();string nextLine;int lineCounter 1;var openPicker new FileOpenPicker();openPicker.SuggestedStartLocation PickerLocationId.DocumentsLibrary;openPicker.FileTypeFilter.Add(.txt);StorageFile selectedFile await openPicker.PickSingleFileAsync();using (StreamReader reader new StreamReader(await selectedFile.OpenStreamForReadAsync())){while ((nextLine await reader.ReadLineAsync()) ! null){contents.AppendFormat({0}. , lineCounter);contents.Append(nextLine);contents.AppendLine();lineCounter;if (lineCounter 3){contents.AppendLine(Only first 3 lines shown.);break;}}}DisplayContentsBlock.Text contents.ToString();}} }Pagex:ClassExampleApplication.BlankPagexmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:localusing:ExampleApplicationxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006mc:IgnorabledStackPanel Background{StaticResource ApplicationPageBackgroundBrush} VerticalAlignmentCenter HorizontalAlignmentCenterTextBlock TextDisplay lines from a file./TextBlockButton ContentLoad File ClickButton_Click_1/ButtonTextBlock NameDisplayContentsBlock/TextBlock/StackPanel /Page
http://www.yutouwan.com/news/152255/

相关文章:

  • 网站开发 0755上海有哪些科技公司
  • 内外网网站栏目建设方案河南省建设科技会网站
  • 厦门的网站轻淘客的轻网站怎么做
  • 建站工具评测 discuz网页搭建模板
  • 广州建设银行官方网站网站备案用的幕布可以淘宝做吗
  • 网广州建网站站制作龙岗网站设计资讯
  • 大连有做途家网站吗全国做膏药的网站有多少家呢
  • 合肥网站建设与设计晋城两学一做网站
  • 自主建站平台18款未成年禁用软件app
  • 静安企业网站制作wordpress网站图片加载速度慢
  • 江津网站建设减压轻松网站开发
  • 关于网站建设的介绍亳州电商网站建设
  • 外国的html 素材网站制作网页的心得
  • 重庆网站设计公司排行龙岩网络公司
  • 设计教育网站网站开发项目税率
  • 青岛做优化网站哪家好网站seo技术教程
  • 网站开发与应用 大作业作业网站建设培训深圳
  • 时尚类网站设计公司惠州哪家做网站比较好
  • 海尔公司的网站建设seo研究中心道一老师
  • 成都金牛区建设局网站深圳燃气公司
  • 网站怎么建设与管理500个企点qq大概多少钱
  • 网站怎么制作公司网站开发费用济南兴田德润o简介图片
  • 网页制作优质网站网站建设与推广策划书
  • 手机跳转网站建设wordpress 微网站模板怎么用
  • 乐清网站制作公司哪家好找做课件的网站
  • 电影网站权重怎么做wordpress 没有远程发布
  • 杭州开发网站的公司南通制作企业网站
  • 网站开发实现的环境php如何做音乐网站
  • 个人网页设计制作题目目的新乡百度网站优化排名
  • 潍坊网站制作保定公司广州最新新闻事件