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

passing parameters to a thread function

P: n/a
Hi all,

I am familiar with passing parameters to a thread function using C++,
but I needt to learn it using C#. Can someone shed some light on
how to do this? Code snippets will be great to show me.

Thanks in advance,

Carlos
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi.

http://www.yoda.arachsys.com/csharp/...rameters.shtml

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Carlos" <ch******@yahoo.com> wrote in message
news:ew****************@TK2MSFTNGP12.phx.gbl...
Hi all,

I am familiar with passing parameters to a thread function using C++,
but I needt to learn it using C#. Can someone shed some light on
how to do this? Code snippets will be great to show me.

Thanks in advance,

Carlos

Nov 17 '05 #2

P: n/a
Carlos wrote:
I am familiar with passing parameters to a thread function using C++,
but I needt to learn it using C#. Can someone shed some light on
how to do this? Code snippets will be great to show me.


class ThreadTest
{
public int i;
public void Threadproc()
{
// use i
}
}

Thread t = new Thread(new ThreadStart(test.Threadproc));
t.Start();

A dirty way to pass parameters to a thread is via the Thread.Name
property, which works, but is not elegant:

Thread t = new Thread(new ThreadStart(Threadproc));
int i = 42;
t.Name = i.ToString();
t.Start();

void Threadproc()
{
int i = Int32.Parse(Thread.CurrentThread.Name);
// use i
}

Of course, if you use a ThreadPool thread, you can pass a parameter.

..NET v2 will allow you to pass a parameter to a thread.

Richard
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.