Can we use thread.start on function that has return value?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

Hi,

Can we use thread.start on a function that has return value?

I have a function that will take sometimes to run and it will return a
string value, and I want to use thread.start to call this function and get
the string, is this possible?


Thanks,
Tee
 
I'm afraid you can't, the ThreadStart delegate has return type void.
You can try BeginInvoke(), EndInvoke(), you can get the return value on
calling EndInvoke(). Or you can write to a common location and use your
own signaling mechanism to indicate that the return value is available.
Regards
Senthil
 
The only way to do this is to create a class that owns and runs the thread.
The class will contain fields or properties that the thread updates and the
calling class will be able to interrogate those fields or properties when
the thread is done. Remember to use mutex to synchronize the access to the
fields within the class so that the thread and the UI thread don't clash.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Back
Top