473,506 Members | 13,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to return to original thread

Is there a way to explicitly tell .NET to return back to
the original calling thread? I am doing asynchronous
threading and I am trying to figure out if I can (within
the callback after the .EndInvoke) explicitly tell .NET to
go back to the thread from where I called the .BeginInvoke.

Thanks,
Bob
Nov 20 '05 #1
3 1176
On Mon, 24 May 2004 15:53:28 -0700, Bob Jacobs wrote:
Is there a way to explicitly tell .NET to return back to
the original calling thread? I am doing asynchronous
threading and I am trying to figure out if I can (within
the callback after the .EndInvoke) explicitly tell .NET to
go back to the thread from where I called the .BeginInvoke.

Thanks,
Bob


Bob,

If this is a GUI app, then yes - there is a way, sort of :) You can do
something similar to this:

' sub in a form, this is air code - and so syntax may be a little off...
Private Sub AsyncCallback(ByVal ar As IAsyncResult)
' call your end invoke

If Me.InvokeRequired Then
Me.Invoke (New AsyncCallbackDelegate(Me.AsyncCallback), ar)
Else
' Do stuff now that you're back on the ui thread
End If
End Sub

--
Tom Shelton [MVP]
Nov 20 '05 #2
Thanks for your answer Tom. I didn't find any property
similar to "me.InvokeRequired" I guess i can pass in the
threadID and compare those, but is there already a system
property on the form that i can use?
Bob,

If this is a GUI app, then yes - there is a way, sort of :) You can dosomething similar to this:

' sub in a form, this is air code - and so syntax may be a little off...Private Sub AsyncCallback(ByVal ar As IAsyncResult)
' call your end invoke

If Me.InvokeRequired Then
Me.Invoke (New AsyncCallbackDelegate (Me.AsyncCallback), ar) Else
' Do stuff now that you're back on the ui thread End If
End Sub

--
Tom Shelton [MVP]
.

Nov 20 '05 #3
In article <12*****************************@phx.gbl>, Bob Jacobs wrote:
Thanks for your answer Tom. I didn't find any property
similar to "me.InvokeRequired" I guess i can pass in the
threadID and compare those, but is there already a system
property on the form that i can use?
Bob,

If this is a GUI app, then yes - there is a way, sort

of :) You can do
something similar to this:

' sub in a form, this is air code - and so syntax may be

a little off...
Private Sub AsyncCallback(ByVal ar As IAsyncResult)
' call your end invoke

If Me.InvokeRequired Then
Me.Invoke (New AsyncCallbackDelegate

(Me.AsyncCallback), ar)
Else
' Do stuff now that you're back on the ui

thread
End If
End Sub

--
Tom Shelton [MVP]

InvokeRequired is a property of the Control class and a member of the
form. I am assuming a GUI here. Other then using the GUI, I can't
really think of a way to go back to another thread.

--
Tom Shelton [MVP]
Nov 20 '05 #4

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

Similar topics

29
2204
by: pmatos | last post by:
Hi all, Sometimes I have a function which creates an object and returns it. Some are sets, other vectors but that's not very important. In these cases I do something like this: vector<int> *...
2
2232
by: Chris | last post by:
I think I already know that the answer is that this can't be done, but I'll ask anyways. Suppose you want to use an RDBMS to store messages for a threaded message forum like usenet and then...
3
1674
by: Felix Kater | last post by:
Hi, normally I use a local variable assigned to different return values inside the function and return it like this: int f(){ int my_err_code; my_err_code=1;
2
1231
by: Lars Netzel | last post by:
I have a ListView in my application. It is populated on Form_Load thru a For Each Loop and in the loop I add a Button to a cell on each row. This works perfect. I have an update button beside...
9
3182
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
14
3452
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
24
2159
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
1
3466
by: Chris Roth | last post by:
I've been working with boost::threads to do some multithreading in my code and have run into some questions that I haven't been able to find answers to. I'll include some sample code to...
68
4551
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
0
7220
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,...
1
7023
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...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
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
3188
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
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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 ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.