|
![](/images/resource/spacer.gif) |
|
C# winApp การใช้ task ในการทำงาน ครับ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ทำได้ แต่จะเร็วขึ้นไหม ไม่รู้ ต้องลองเอง (อาจทดสอบกับปริมาณน้อยๆ)
Code (C#)
string[] folders = Directory.GetDirectories("C:\\myfolder");
for (int i = 0; i < folders.Length; i++)
{
string currentFolder = folders[i];
string nextFolder = (i < folders.Length - 1) ? folders[i + 1] : null;
// Start copying files from the current folder asynchronously
Task.Run(() => CopyFiles(currentFolder, nextFolder));
}
private void CopyFiles(string sourceFolder, string targetFolder)
{
// Get the list of files in the source folder
string[] files = Directory.GetFiles(sourceFolder);
foreach (string file in files)
{
// Copy the file to the target folder
string fileName = Path.GetFileName(file);
string destFile = Path.Combine(targetFolder, fileName);
File.Copy(file, destFile, true);
}
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2023-04-05 20:19:20 |
By :
009 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 01
|