using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace StreamWin
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string filePaths = @"E:\Test\Test\local\a.txt";
string fileName ="a.txt" ;
System.IO.FileInfo f = new FileInfo(@"E:\Test\Test\server\a.txt");
int fileLength = Convert.ToInt32(f.Length.ToString());
ThreadPool.SetMaxThreads(100, 100);
using (System.IO.FileStream stream = new System.IO.FileStream(filePaths, FileMode.Create,FileAccess.Write, FileShare.Write, 1024, true))
{
for (int i = 0; i < fileLength; i +=100 * 1024)
{
int length = (int)Math.Min(100 * 1024, fileLength - i);
var bytes = GetFile(fileName, i, length);
stream.BeginWrite(bytes, 0, length, new AsyncCallback(Callback), stream);
}
stream.Flush();
}
}
public static byte[] GetFile(string name, int start, int length)
{
string filepath = @"E:\Test\Test\server\a.txt";
using (System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite,1024,true))
{
byte[] buffer = new byte[length];
fs.Position = start;
fs.BeginRead(buffer, 0, length,new AsyncCallback(Completed),fs);
return buffer;
}
}
static void Completed(IAsyncResult result)
{
FileStream fs = (FileStream)result.AsyncState;
fs.EndRead(result);
fs.Close();
}
public static void Callback(IAsyncResult result)
{
FileStream stream = (FileStream)result.AsyncState;
stream.EndWrite(result);
stream.Close();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有