473,569 Members | 2,383 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 1183
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(B yVal ar As IAsyncResult)
' call your end invoke

If Me.InvokeRequir ed Then
Me.Invoke (New AsyncCallbackDe legate(Me.Async Callback), 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.InvokeRequi red" 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(B yVal ar As IAsyncResult)
' call your end invoke

If Me.InvokeRequir ed Then
Me.Invoke (New AsyncCallbackDe legate (Me.AsyncCallba ck), 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.InvokeRequi red" 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(B yVal ar As IAsyncResult)
' call your end invoke

If Me.InvokeRequir ed Then
Me.Invoke (New AsyncCallbackDe legate

(Me.AsyncCallba ck), 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
2210
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> * f() { vector<int> * v = new vector<int>; return v; }
2
2239
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 display the messages. A toy table definition (that I've tried to make standards compliant) might look like: create table messages ( message_id...
3
1680
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
1236
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 the ListView that, when clicked, starts a new thread that reads thru a bunch of files and emails.. and when this is done it repopulates the ListView....
9
3195
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. What it does is to call a webservice with two parameters, one being a integer, the other one being a "String" which contains XML (not the best...
14
3455
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 public member with a return type that is derived from System.Exception? I understand the importance of having clean, concise code that follows...
24
2177
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 the UI layer to a method in a library class that calls the stored procedure. Best to return a boolean indicating success/failure, return a string with...
1
3468
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 illustrate my questions. #include <boost/thread/thread.hpp> #include <iostream> using namespace std;
68
4575
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 temporary but it was stated that it would not. This has come up in an irc channel but I can not find the original thread, nor can I get any code to...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7678
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5222
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2116
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 we have to send another system
0
944
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.