2

I want to create threads and assign different function for each thread using c#?

0

4 Answers 4

5

Unless you have good reasons for creating threads, you should prefer using the managed thread pool instead and if .NET 4 is an option, you should take a look at the new Task class.

Sign up to request clarification or add additional context in comments.

Comments

2
 Thread T = new Thread(SomeFunction); T.Start(); 

1 Comment

if functions has many arguments like this function : sent_to_server(string init_message, List<string> all_action_messages, byte[] buffer, ASCIIEncoding encoder, NetworkStream clientStream)
1

Absolutely using the new Task class in .net 4 is the easiest way.

Task.Factory.StartNew(() => mymethod()); 

Comments

0
var delegates = new []{NamedMethod1, NamedMethod2, ()=>DoSomething()} var threads = new List<Thread>(); foreach(var theDelegate in delegates) threads.Add(new Thread(theDelegate)); foreach(var thread in threads) thread.Start(); foreach(var thread in threads) thread.Join(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.