hi,all

this is a stupid question.

I want to use thread
when I create a new ThreadStart,

ThreadStart thread = new System.ThreadThreading.ThreadStart(ThreadProc)

I want to pass some parameter to ThreadProc
how to do it?

thanks

Re: Threading by Francois

Francois
Thu Jun 23 08:46:51 CDT 2005

if all you need is to share some data with ThreadProc, you should declare a
class variable that will be assigned the data. (watch out for
synchronisation issues if you are going to be modifying the value in
question).

if you absolutely want to pass some parameters, you should declare a
delegate for the method you want to call and use the BeginInvoke method.
Like this:


public class example
{
private void mythreadmethod(string someparam)
{
//do whatever
}

public delegate void ParamMethod(string someParam);

public static void Main()
{
example ex = new example();
ParamMethod pm = new ParamMethod(ex.mythreadmethod);
string argToPass = "hello";
pm.BeginInvoke(argToPass, null, null);
}
}

This is a very simple example (for example, a lot can be said about the last
2 parameters of the BeginInvoke method ...) but it illustrates what you need

HTH
Cois

"jeff" <jeff@discussions.microsoft.com> wrote in message
news:DDA029C4-FB57-4206-9757-A1F3C7F59F25@microsoft.com...
> hi,all
>
> this is a stupid question.
>
> I want to use thread
> when I create a new ThreadStart,
>
> ThreadStart thread = new System.ThreadThreading.ThreadStart(ThreadProc)
>
> I want to pass some parameter to ThreadProc
> how to do it?
>
> thanks



Re: Threading by Jon

Jon
Thu Jun 23 13:11:49 CDT 2005

jeff <jeff@discussions.microsoft.com> wrote:
> this is a stupid question.

Not at all :)

> I want to use thread
> when I create a new ThreadStart,
>
> ThreadStart thread = new System.ThreadThreading.ThreadStart(ThreadProc)
>
> I want to pass some parameter to ThreadProc how to do it?

See http://www.pobox.com/~skeet/csharp/threads/parameters.shtml

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: Threading by Flip

Flip
Fri Jun 24 10:20:41 CDT 2005

> See http://www.pobox.com/~skeet/csharp/threads/parameters.shtml


My head spins with multithreading issues as well. I'm going to read your
link over lunch. Thank you for the link! :>