111,126
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 2; i++)
{
string aa = "";
string bb = "";
if (i == 0)
{
aa = "E:\\bak\\a\\test.xml";
bb = "E:\\bak\\c\\a.xml";
}
else if (i == 1)
{
aa = "E:\\bak\\b\\test2.txt";
bb = "E:\\bak\\d\\wy.txt";
}
//COPY局部变量
string a = aa, b = bb;
int ti = i;
Thread t = new Thread(() => { copyfile(a, b, ti); });
t.Start();
}
}
private static object sync = new object();
public void ssavefile( string path1,string path2)
{
lock(sync)
{
File.Copy(path1, path2);
}
}
private void copyfile( string path1,string path2 ,int type )
{
File.Copy(path1, path2);
if (type == 0)
{
Class1 c1 = new Class1();
c1.ssavefile(path2, "E:\\bak\\e\\20090420.xml");
}
else if (type == 1)
{
Class1 c1 = new Class1();
c1.ssavefile(path2, "E:\\bak\\f\\20090420.txt");
}
}