forodo
جمعه 04 بهمن 1392, 18:56 عصر
سلام
من متوجه نمی شم چطوری باید کدای زیر رو داخل Thread قرار بدم که وقتی عملیات کپی داره انجام می شه بتونم با برنامه ام کار کنم و صبر نکنه که کپی تموم بشه و دسترسی به برنامه ام رو برگردونه.
من اینجوری نوشتم:
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(CopyFolderAndIcon));
t.Start();
MessageBox.Show("Test");
}
این هم اون تابعم هستش:
private void CopyFolderAndIcon()
{
// ساخت شی از کنترل فولدربروزردیالوگ
FolderBrowserDialog fbd = new FolderBrowserDialog();
// دادن توضیحات به کنترل فولدربروزردیالوگ
fbd.Description = "Copy Films Of Ali";
// اگر فولدربروزردیالوگ اوکی بود
if (fbd.ShowDialog() == DialogResult.OK)
{
// اگر فولدر کپی می شود
if (Directory.Exists(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()))
{
#region ساخت آیکون فولدر
FolderIcon myFolderIcon = new FolderIcon(fbd.SelectedPath + "\\" + Path.GetFileName(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()));
myFolderIcon.CreateFolderIcon(radGridView2.Current Row.Cells["FilePath"].Value.ToString() + @"\FolderMarker.ico");
myFolderIcon = null;
#endregion
#region کپی کردن فولدر با تمام زیرشاخه هایش
DirectoryInfo di = new DirectoryInfo(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString());
DirectoryInfo di1 = new DirectoryInfo(fbd.SelectedPath + "\\" + Path.GetFileName(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()));
RunFileOrFolder.tek = radGridView2.CurrentRow.Cells["FilePath"].Value.ToString();
RunFileOrFolder.CopyDirectory(di, di1);
#endregion
// پیغام اتمام کپی
MessageBox.Show("finish");
}
// اگر فایل کپی می شود
else if (File.Exists(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()))
{
#region کپی فایل
FileInfo fi = new FileInfo(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString());
if (Directory.Exists(fbd.SelectedPath))
{
fi.CopyTo(fbd.SelectedPath + "\\" + Path.GetFileName(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()));
MessageBox.Show("finish File");
}
else
{
MessageBox.Show("There is no selected path", "Path", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#endregion
}
}
}
من متوجه نمی شم چطوری باید کدای زیر رو داخل Thread قرار بدم که وقتی عملیات کپی داره انجام می شه بتونم با برنامه ام کار کنم و صبر نکنه که کپی تموم بشه و دسترسی به برنامه ام رو برگردونه.
من اینجوری نوشتم:
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(CopyFolderAndIcon));
t.Start();
MessageBox.Show("Test");
}
این هم اون تابعم هستش:
private void CopyFolderAndIcon()
{
// ساخت شی از کنترل فولدربروزردیالوگ
FolderBrowserDialog fbd = new FolderBrowserDialog();
// دادن توضیحات به کنترل فولدربروزردیالوگ
fbd.Description = "Copy Films Of Ali";
// اگر فولدربروزردیالوگ اوکی بود
if (fbd.ShowDialog() == DialogResult.OK)
{
// اگر فولدر کپی می شود
if (Directory.Exists(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()))
{
#region ساخت آیکون فولدر
FolderIcon myFolderIcon = new FolderIcon(fbd.SelectedPath + "\\" + Path.GetFileName(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()));
myFolderIcon.CreateFolderIcon(radGridView2.Current Row.Cells["FilePath"].Value.ToString() + @"\FolderMarker.ico");
myFolderIcon = null;
#endregion
#region کپی کردن فولدر با تمام زیرشاخه هایش
DirectoryInfo di = new DirectoryInfo(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString());
DirectoryInfo di1 = new DirectoryInfo(fbd.SelectedPath + "\\" + Path.GetFileName(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()));
RunFileOrFolder.tek = radGridView2.CurrentRow.Cells["FilePath"].Value.ToString();
RunFileOrFolder.CopyDirectory(di, di1);
#endregion
// پیغام اتمام کپی
MessageBox.Show("finish");
}
// اگر فایل کپی می شود
else if (File.Exists(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()))
{
#region کپی فایل
FileInfo fi = new FileInfo(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString());
if (Directory.Exists(fbd.SelectedPath))
{
fi.CopyTo(fbd.SelectedPath + "\\" + Path.GetFileName(radGridView2.CurrentRow.Cells["FilePath"].Value.ToString()));
MessageBox.Show("finish File");
}
else
{
MessageBox.Show("There is no selected path", "Path", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#endregion
}
}
}