By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,677 Members | 1,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,677 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Jul 21 '05 #2

P: n/a
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.

"Tee" <th*@streamyx.com> wrote in message
news:u1****************@TK2MSFTNGP10.phx.gbl...
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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.