你是说另开一个线程吧?
static void Move(Object args)
{
string[] files = (string[])args;
File.Move(files[0], files[1]);
}
调用::
string[] files={"C:\\a.txt","C:\\b.txt"}; Thread t = new Thread(new ParameterizedThreadStart(Move));
t.Start(files);
static void Move(Object args)
{
string[] files = (string[])args;
File.Move(files[0], files[1]);
}
调用::
string[] files={"C:\\a.txt","C:\\b.txt"}; Thread t = new Thread(new ParameterizedThreadStart(Move));
t.Start(files);
解决方案 »
- [求助]如何让用户自己选择连接哪个数据库?
- 【求助】FileSystemWatcher同时监控两个目录的方法
- 怎么改变dockpanel 的主PANEL的颜色?(具体见图)
- Socket通信(c#)在windows平台上,最大能支持多少人同时在线
- 如何在应用master页面中访问master页面中的控件?
- 加载设计器时遇到一个或多个错误。这些错误在下面列出。一些错误可通过重新生成项目来修复,而另一些错误则需要更改代码
- 怎么从config中读数据库联接字符串.
- c#如何实现把更新好的外部应用程序先关闭再启动?
- 急!水晶报表在win98下如何显示(winform)!!!!!!!!!!!!!!!!!!!
- 控件类RichControl在那里啊?
- UpdatePanel中按钮点第一次有效果点第二次就没有效果
- 2010的调用层次结构编码实现问题,比较难
static void A()
{
File.Move("","");
}
new Thread((ThreadStart)delegate
{File.Move("","");
}).Start();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
namespace Text
{
public class CopyThread
{
private CopyObject copyObjects;
public CopyObject CopyObjects
{
get
{
return copyObjects;
}
set
{
copyObjects = value;
}
} public void Run()
{
Thread ThRead = new Thread(new ParameterizedThreadStart(CopyEvents_ReadEvent));
ThRead.Start(CopyObjects);
} //复制写的方法
void CopyEvents_WriteEvent(object COB)
{
CopyObject obj = (CopyObject)COB;
using (FileStream fs = new FileStream(obj.Target_FileName, FileMode.Append, FileAccess.Write, FileShare.Write))
{
fs.Write(obj.File_bytes, 0, obj.File_bytes.Length);
fs.Close();
}
} //复制读的方法
void CopyEvents_ReadEvent(object COB)
{
CopyObject obj = (CopyObject)COB;
using (FileStream fs = new FileStream(obj.Filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
long len = fs.Length;
//定义开始的长度为0字节
long wLen = 0;
//定义一次性读取1048576个字节
long bytLen = 1048576000;
while (wLen < len)
{
//Position规定他是一个从0开始的索引
long pos = fs.Position;
wLen += bytLen;
if (wLen > len)
{
bytLen = len - pos;
wLen = len;
}
byte[] byt = new byte[bytLen];
fs.Read(byt, 0, byt.Length);
fs.Seek(wLen, SeekOrigin.Begin);
obj.File_bytes = byt; Thread ThWrite = new Thread(new ParameterizedThreadStart(CopyEvents_WriteEvent));
ThWrite.Start(obj);
}
fs.Close();
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
namespace Text
{
//定义了一个读写委托。
delegate void Read(CopyObject obj);
delegate void Write(CopyObject obj);
public class CopyEvents
{
private event Read ReadEvent;
private event Write WriteEvent;
//定义一个复制的对象
public CopyObject copyObjects;
public CopyObject CopyObjects
{
get
{
return copyObjects;
}
set
{
copyObjects = value;
}
} //定义一个Run方法
public void Run()
{
ReadEvent += new Read(CopyEvents_ReadEvent);
WriteEvent += new Write(CopyEvents_WriteEvent);
Thread Th = new Thread(new ThreadStart(Execute_Copy));
Th.Start();
} //定义一个执行复制的方法
public void Execute_Copy()
{
ReadEvent(CopyObjects);
} //定义一个执行复制写的事件
void CopyEvents_WriteEvent(CopyObject obj)
{
using (FileStream fs = new FileStream(obj.Target_FileName, FileMode.Append, FileAccess.Write, FileShare.Write))
{
fs.Write(obj.File_bytes,0,obj.File_bytes.Length);
fs.Close();
}
} //定义一个执行复制读的事件
void CopyEvents_ReadEvent(CopyObject obj)
{
using (FileStream fs = new FileStream(obj.Filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
long len = fs.Length;
//定义开始的长度为0字节
long wLen = 0;
//定义一次性读取1048576个字节
long bytLen = 1048576000;
while (wLen < len)
{
long pos = fs.Position;
wLen += bytLen;
if (wLen > len)
{
bytLen = len - pos;
wLen = len;
}
byte[] byt = new byte[bytLen];
fs.Read(byt, 0, byt.Length);
fs.Seek(wLen, SeekOrigin.Begin);
obj.File_bytes = byt;
WriteEvent(obj);
}
fs.Close();
}
}
} public class CopyObject
{
//定义开始的文件字节大小
private byte[] file_bytes; public byte[] File_bytes
{
get
{
return file_bytes;
}
set
{
file_bytes = value;
}
}
private string filename; public string Filename
{
get
{
return filename;
}
set
{
filename = value;
}
}
private string target_FileName; public string Target_FileName
{
get
{
return target_FileName;
}
set
{
target_FileName = value;
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
namespace Text
{
public class test
{
public static void Main()
{
CopyObject CO = new CopyObject();
CO.Filename = "A.txt";
CO.Target_FileName = "B.txt";
test t = new test();
t.Copy(CO);
}
private void Copy(CopyObject Obj)
{
//用事件
//CopyEvents CE = new CopyEvents();
//CE.CopyObjects = Obj;
//CE.Run(); //用线程
CopyThread CT = new CopyThread();
CT.CopyObjects = Obj;
CT.Run();
}
}
}