473,508 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
Nov 16 '05 #1
4 24258
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

Nov 16 '05 #2
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

Nov 16 '05 #3
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

Nov 16 '05 #4
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

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3433
by: Jonas | last post by:
Dear members, How can I use a function return value in a regexpr? $tmp=~s/mysearch/myfunction($1)/; sub myfunction { return $v; }
1
2609
by: Tropos | last post by:
Query: Will a MutexGuard object release before a function return value is copied? Consider the C++ code: class MutexGuard //A familiar sort of class for making mutexes exception-safe { . ....
4
4279
by: wongjoekmeu | last post by:
Hello All, I know that when you pass an argument to a function (if you want let the function be able to change the value) then you can choose to pass the argument by reference or a pointer to...
4
45160
by: bluedolphin | last post by:
This is my first function in Visual and I'm having a simple syntax syntax issue that I'm hoping someone can help correct for me. I have a function Public Function...
8
13986
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
7
1704
by: chellappa | last post by:
hi this program return value automatically ... how it is possible ..i am not return any value... but i return correct values i am using Linux -gcc complier please tell me what is this main() {...
11
2746
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
8
2046
by: bdobby | last post by:
Hi. I am relatively new to js, but I did think I was starting to get the hang of it. Then this happened... I have a form with an onsubmit event handler: <form id="uploadForm" method="post"...
4
1634
by: pradeep | last post by:
Hello friends ~ We know that a C function will return a 32-bit value from a function in %eax and a 64-bit value in %edx:%eax. But what about larger return types, for example large structs? The...
6
18975
by: kurt.krueckeberg | last post by:
Can someone explain why this line $bool = isset($_POST) && !empty(trim($_POST)); causes the error message "Can't use function return value in write context". trim() returns a string. I test if it...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.