launch a thread with a NON-VOID method?

  • Thread starter Thread starter titan nyquist
  • Start date Start date
T

titan nyquist

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 said:
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.
 
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
 
Return to whom?
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
 
titan nyquist said:
So you cannot use a non-void directly?
No.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top