Click here to Skip to main content
15,920,005 members
Home / Discussions / C#
   

C#

 
AnswerRe: Passing methods to ThreadStart - Possible? Pin
Judah Gabriel Himango2-May-05 9:05
sponsorJudah Gabriel Himango2-May-05 9:05 
Yes, but not with Thread.Start (although you can in .NET 2.0, because Thread.Start will have overloads to take a ParameterizedThreadStart, which allows you to pass a System.Object parameter).

For .NET 1.x code, you have 2 options.

You could use the built-in .NET threadpool:

void SomeMethod(object parameter)
{
   // Assume we passed in an int[].
   int[] typedParam = (int[])parameter;
}

WaitCallback waitCallback = new WaitCallback(SomeMethod);
ThreadPool.QueueUserWorkItem(waitCallback, new int[]{1, 5});


Or you can define your own delegate (or use an existing one) that matches your desired method signature (i.e. has the correct number of parameters and the correct parameter types), then call delegate.BeginInvoke on it:

delegate void MethodWithTwoIntegers(int a, int b);

void SomeMethod(int a, int b)
{
}

MethodWithTwoIntegers myMethod = new MethodWithTwoIntegers(SomeMethod);
myMethod.BeginInvoke(5, 10, null, null);


Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango


AnswerRe: Passing methods to ThreadStart - Possible? Pin
Marc Clifton2-May-05 10:52
mvaMarc Clifton2-May-05 10:52 
AnswerRe: Passing methods to ThreadStart - Possible? Pin
leppie2-May-05 14:29
leppie2-May-05 14:29 
GeneralGeneric Hashtable Pin
Anonymous2-May-05 8:48
Anonymous2-May-05 8:48 
GeneralRe: Generic Hashtable Pin
Marc Clifton2-May-05 10:53
mvaMarc Clifton2-May-05 10:53 
GeneralRe: Generic Hashtable Pin
Anonymous3-May-05 5:09
Anonymous3-May-05 5:09 
GeneralRe: Generic Hashtable Pin
leppie2-May-05 14:46
leppie2-May-05 14:46 
GeneralOle Server Pin
BigAnyon2-May-05 5:58
BigAnyon2-May-05 5:58 
GeneralVisual style icons / bitmaps Pin
Anonymous2-May-05 5:45
Anonymous2-May-05 5:45 
GeneralRe: Visual style icons / bitmaps Pin
Judah Gabriel Himango2-May-05 7:05
sponsorJudah Gabriel Himango2-May-05 7:05 
GeneralRe: Visual style icons / bitmaps Pin
MoustafaS2-May-05 8:49
MoustafaS2-May-05 8:49 
GeneralEasy file I/O Pin
briggs_w2-May-05 4:58
briggs_w2-May-05 4:58 
GeneralRe: Easy file I/O Pin
Heath Stewart2-May-05 5:11
protectorHeath Stewart2-May-05 5:11 
GeneralRe: Easy file I/O Pin
Marc Clifton2-May-05 5:24
mvaMarc Clifton2-May-05 5:24 
General... also ... Pin
Marc Clifton2-May-05 5:26
mvaMarc Clifton2-May-05 5:26 
GeneralRe: Easy file I/O Pin
briggs_w5-May-05 5:50
briggs_w5-May-05 5:50 
GeneralAccess a flat file at http location Pin
mrinmayeek2-May-05 4:27
mrinmayeek2-May-05 4:27 
GeneralRe: Access a flat file at http location Pin
Heath Stewart2-May-05 5:12
protectorHeath Stewart2-May-05 5:12 
GeneralControl Instantiation Pin
terrier_jack2-May-05 4:25
terrier_jack2-May-05 4:25 
GeneralRe: Control Instantiation Pin
Marc Clifton2-May-05 5:08
mvaMarc Clifton2-May-05 5:08 
GeneralRe: Control Instantiation Pin
MoustafaS2-May-05 8:54
MoustafaS2-May-05 8:54 
GeneralHTML control Pin
Anonymous2-May-05 3:39
Anonymous2-May-05 3:39 
GeneralRe: HTML control Pin
Heath Stewart2-May-05 5:16
protectorHeath Stewart2-May-05 5:16 
QuestionHow to Connect Managed and UnManaged code for Socket Programming Pin
Shashidharreddy2-May-05 3:08
Shashidharreddy2-May-05 3:08 
AnswerRe: How to Connect Managed and UnManaged code for Socket Programming Pin
S. Senthil Kumar2-May-05 3:51
S. Senthil Kumar2-May-05 3:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.