PC Review


Reply
Thread Tools Rate Thread

Customize the StartProc for thread

 
 
Zeng
Guest
Posts: n/a
 
      19th Mar 2005
Hello,

Is there a way to pass something to the StartProc below for each new thread
that I create? Something like 'code' below. Thanks for any comment or
advice!

static void StartProc( int code )
{
if( code > 0 )
{
// do something
}
}

Thread t = new Thread( new ThreadStart(StartProc));
t.Start();


 
Reply With Quote
 
 
 
 
hiriumi@gmail.com
Guest
Posts: n/a
 
      19th Mar 2005
You could use a property, but then StartProc is a static method, so the
only way you can do this is by using delegate because delegate can take
parameters. Try to do some research on delegate online and get some
samples. I'm sure there is a lot out there.

 
Reply With Quote
 
Zeng
Guest
Posts: n/a
 
      19th Mar 2005
I'm still not clear on how to pass in something (id, string etc...) to the
StartProc. The ThreadStart is defined by .net and it's a delegate of
no-parameter method type.




<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You could use a property, but then StartProc is a static method, so the
> only way you can do this is by using delegate because delegate can take
> parameters. Try to do some research on delegate online and get some
> samples. I'm sure there is a lot out there.
>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      19th Mar 2005
Zeng <(E-Mail Removed)> wrote:
> I'm still not clear on how to pass in something (id, string etc...) to the
> StartProc. The ThreadStart is defined by .net and it's a delegate of
> no-parameter method type.


See http://www.pobox.com/~skeet/csharp/t...rameters.shtml

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Leonid Finis
Guest
Posts: n/a
 
      20th Mar 2005
ThreadStart IS defined as no-parameter delegate, but it can belong to
statfull instance of a class, so that instance can carry context information
for the Thread procedure.

Leonid Finis.


"Zeng" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I'm still not clear on how to pass in something (id, string etc...) to the
> StartProc. The ThreadStart is defined by .net and it's a delegate of
> no-parameter method type.
>
>
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> You could use a property, but then StartProc is a static method, so the
>> only way you can do this is by using delegate because delegate can take
>> parameters. Try to do some research on delegate online and get some
>> samples. I'm sure there is a lot out there.
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ShowDialog - Cross-thread operation not valid: Control'CheckAccountInfo' accessed from a thread other than the thread it was createdon. Tom C Microsoft C# .NET 9 20th Feb 2008 08:15 PM
HELP - Why are Worker thread's child thread's entering WaitSleepJoin? Plus Context Deadlock.... hzgt9b Microsoft VB .NET 0 28th Sep 2007 07:21 PM
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on Joe Microsoft C# .NET 4 12th Mar 2007 09:59 AM
Thread A calls a delegate on Thread B but Thread A executes it!?!? Paul Tomlinson Microsoft C# .NET 4 3rd Feb 2005 10:09 PM
Shut down thread - thread closes form, form doesn't close because thread calls it etc... Robin Tucker Microsoft VB .NET 4 17th Oct 2003 12:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:08 AM.