Below is a simple example:

    int Parallel_Count = int.Parse(nudParallelCount.Text);
    for (int i = 1; i <= Parallel_Count; i++)
    {
        Thread string.Format("Thread_{0}", i) = new Thread(new ThreadStart(string.Format("Thread_{0}_Inside", i) ));
        string.Format("Thread_{0}", i).Start();
    }

As you see I did not use regular names for thread names and their entries and my codes have error because of them.

I want to add a counter (as a string) to thread names and thread entries names.

EDIT
One of my entries is like this :

    public void Thread_1_Inside()
    {
          bloblobloblo -> i've created this expression by myself :)
    }
有帮助吗?

解决方案

You are looking for a container like an array or a list. Please make sure you understand those structures before you go into threading because they are pretty basic constructs and threading is tough stuff.

int Parallel_Count = int.Parse(nudParallelCount.Text);

Thread[] threads = new Thread[Parallel_Count];

for (int i = 0; i < Parallel_Count; i++)
{
    threads[i] = new Thread(/*fill thread start here*/);
    threads[i].Start();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top