By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,221 Members | 1,315 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,221 IT Pros & Developers. It's quick & easy.

passing parameter to thread ??

P: n/a
Hi,

Is there a way to pass a parameter to a thread ?

Creating a thread is done using a ThreadStart-delegate object

example :
Thread thread1 = new Thread(new ThreadStart(MyFunction))

Unfortunately, it doesn't allow me to pass arguments to MyFunction since the definition of the ThreadStart is :
public delegate void ThreadStart();

Is there a way, anyhow, to pass a parameter to a thread ?
Using some other mechanism ?

thnx
Christian

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Diving in before Jon does ;-)

http://www.yoda.arachsys.com/csharp/threadstart.html

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<#W**************@tk2msftngp13.phx.gbl>

Hi,

Is there a way to pass a parameter to a thread ?

Creating a thread is done using a ThreadStart-delegate object

example :
Thread thread1 = new Thread(new ThreadStart(MyFunction))

Unfortunately, it doesn't allow me to pass arguments to MyFunction since the definition of the ThreadStart is :
public delegate void ThreadStart();

Is there a way, anyhow, to pass a parameter to a thread ?
Using some other mechanism ?

thnx
Christian

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.768 / Virus Database: 515 - Release Date: 22/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #2

P: n/a
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Also, in .NET 2.0, the Thread class has an overloads for the constructor
and the Start methods to allow for the ParameterizedThreadStart delegate,
which allows a parameter to be passed to the thread routine.


Oh, nice - cheers, I'll add looking into that onto my list of things to
do for the multithreading pages :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.