使用异步读写实现文件的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回调方法
IAsyncResult readResult = sourceFile.BeginRead(byDataIn, 0, 100