Hello Anoymous_Praveen:
You should define a class that accepts 100 folders as a string array and do to process, then expose an event to be handled when the thread is finished. Now check the simiar sample:
using System.Threading;
using System.Xml;
namespace MultiCore
{
public class ThreadClass
{
/// <summary>
/// Expose the processed folders for futher process
/// </summary>
public string[]Folders{get;private set;}
/// <summary>
/// Expose the event to be handled
/// </summary>
public event System.Action<string[]> ProcessFinished = null;
/// <summary>
/// Constructor for initialization
/// </summary>
/// <param name="_folders">the folders to be processed</param>
public ThreadClass(string[]_folders)
{
Folders = _folders;
}
/// <summary>
/// Do processing
/// </summary>
public void Run()
{
Thread th = new Thread(() =>
{
foreach (var item in Folders)
{
//Do process with item folder and all of its file by Directory.GetFiles
}
//When finished, raise the event to pass all the string values to UI through the event and notify that the thread is finished for futher combination
if (ProcessFinished != null)
{
this.Invoke(new MethodInvoker(()=>{ProcessFinished(Folders)}));
}
});
th.IsBackground = true;
th.Start();
}
}
class MainTest
{
static void Main(string[] args)
{
//Initailize 4 class instance as what I gave you here below:
ThreadClass tc = new ThreadClass(Your Folder String Array);
//Handle the event to notify that the thread is finished
tc.ProcessFinished+=new System.Action<string[]>(tc_ProcessFinished);
}
static void tc_ProcessFinished(string[] arg)
{
//Do process with "arg" as processed value, if necessary.
}
}
}
Click For donating:Free Rice For the poor
For spamming-sender issues, you can either report it at Microsoft Spamming Issue , or just find "Report Spam Here+Number" at Forum Issue ;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
For more things to talk about? StackOverFlow is your choice.
No comments:
Post a Comment