使用异步读写实现文件的Copy:
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
public class AsyncReadWrite
{
byte[] byDataIn;
byte[] byDataOut;
char[] charData;
public AsyncReadWrite()
{
byDataIn = new byte[100];
charData = new Char[100];
byDataOut = new byte[100];
try
{
FileStream sourceFile = new FileStream("F://source.txt", FileMode.Open, FileAccess.Read);
FileStream targetFile = new FileStream("F://target.txt", FileMode.Open, FileAccess.Write);
AsyncCallback readCallBack = new AsyncCallback(this.HandleRead); //read回调方法
AsyncCallback writeCallBack = new AsyncCallback(this.HandleWrite); //write回调方法
&

此博客展示了如何使用C#.net的异步读写操作实现文件的复制。通过创建FileStream对象并使用BeginRead和BeginWrite方法启动异步读写过程,结合回调函数HandleRead和HandleWrite处理读写完成后的操作。

322

被折叠的 条评论
为什么被折叠?



