Connecting Tech Pros Worldwide Help | Site Map

launch a thread with a NON-VOID method?

titan nyquist
Guest
 
Posts: n/a
#1: Apr 16 '07
I have launched threads with void methods, like so:

TestClass testClass = new TestClass();
Thread testThread = new Thread(testClass.Launch);
testThread.Start();

Where testClass.Launch is void, this works.

I want to make testClass.Launch return a value (bool). Can I do this?

Titan

Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#2: Apr 16 '07

re: launch a thread with a NON-VOID method?


titan nyquist <titan.nyquist@gmail.comwrote:
Quote:
I have launched threads with void methods, like so:
>
TestClass testClass = new TestClass();
Thread testThread = new Thread(testClass.Launch);
testThread.Start();
>
Where testClass.Launch is void, this works.
>
I want to make testClass.Launch return a value (bool). Can I do this?
Just use a void method which calls the non-void method - or use an
anonymous method to do the same thing.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
titan nyquist
Guest
 
Posts: n/a
#3: Apr 16 '07

re: launch a thread with a NON-VOID method?


So you cannot use a non-void directly?

How would I get the return value from the non-void method, if I call
it from the void method?

Thanks,
Titan

Ignacio Machin \( .NET/ C# MVP \)
Guest
 
Posts: n/a
#4: Apr 16 '07

re: launch a thread with a NON-VOID method?


Hi,


Return to whom?

The calling method will be gone by then.

"titan nyquist" <titan.nyquist@gmail.comwrote in message
news:1176747532.869558.200930@n59g2000hsh.googlegr oups.com...
Quote:
>I have launched threads with void methods, like so:
>
TestClass testClass = new TestClass();
Thread testThread = new Thread(testClass.Launch);
testThread.Start();
>
Where testClass.Launch is void, this works.
>
I want to make testClass.Launch return a value (bool). Can I do this?
>
Titan
>

titan nyquist
Guest
 
Posts: n/a
#5: Apr 16 '07

re: launch a thread with a NON-VOID method?


Return to whom?
Quote:
>
The calling method will be gone by then.
Good point... I need to rethink what I was trying to do.

My errors should be handled inside of the thread, not outside of the
thread in the caller.

Titan

Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#6: Apr 16 '07

re: launch a thread with a NON-VOID method?


titan nyquist <titan.nyquist@gmail.comwrote:
Quote:
So you cannot use a non-void directly?
No.
Quote:
How would I get the return value from the non-void method, if I call
it from the void method?
You'll need to store it somewhere that the other thread can get at.
Bear in mind that you'll also need to work out when the other thread
has finished - the value won't be available immediately.

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