473,657 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

thread invoke Synch marshalling

Hi all,

I'm trying to trigger an event from threadB which will be processed by
threadA. It sounds simple, but I cannot seem to find any documentation about
this anywhere.

This is very much like what the windows controls have with InvokeRequired
and then invoke from the current thread. Although I can see that it's not
running on threadA by comparing threadIDs I can't find how to invoke the
method from threadA instead of threadB. I want to be able to do this without
using wait methods to wait for events, instead just pushing the event onto
that threads stack.

Any Ideas?

Aug 25 '06 #1
1 1927

"Paul" <pm*******@hotm ail.comwrote in message
news:e2******** ******@TK2MSFTN GP03.phx.gbl...
Hi all,

I'm trying to trigger an event from threadB which will be processed by
threadA. It sounds simple, but I cannot seem to find any documentation
about this anywhere.

This is very much like what the windows controls have with InvokeRequired
and then invoke from the current thread. Although I can see that it's not
running on threadA by comparing threadIDs I can't find how to invoke the
method from threadA instead of threadB. I want to be able to do this
without using wait methods to wait for events, instead just pushing the
event onto that threads stack.
The canonical way of doing this is by posting to the thread's message queue.
While you could theoretically suspend the thread, update its context, etc,
etc, that is 99.999% certain to create bugs. What if that thread holds a
lock on a shared resource? There are no synchronization primitives provided
to help you with this. Your event handlers would have to be written like
interrupt service routines, and even so, most API calls would not be
available to you since they modify state that would trash whatever work the
thread was doing. Even then, the other thread is not required to run
instantly, but could be scheduled later. If you really need synchronous
events, make the call from your own thread and use proper synchronization .

What I think you'd ultimately find is that there are certain places where
the thread cannot afford to be interrupted. Win32 API already provides for
context-switching and provides critical sections, mutexes, semaphores,
events to help you manage shared state. Don't try to re-implement all that
yourself.
>

Any Ideas?

Aug 25 '06 #2

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

Similar topics

2
3218
by: Michel Schilthuizen | last post by:
Hi, I am working on an application that can use functionlity in some sort of plugins. I have implemented this by using Assembly.LoadFrom and MethodInfo.GetMethods. The calling of the plugins is handled in threads. All works fine, but when I call a method that processes for some time, the mainthread (my form) becomes unresponsive.
8
2384
by: Mountain Bikn' Guy | last post by:
I'm using async delegate calls. I would like to re-enter my initial thread after the callback. (I'm not using UI controls, so Control.Invoke is not the solution.) How can I manually implement behavior like Control.Invoke? How can I re-enter my initial thread? Any suggestions? Thanks! Mountain I already searched Google Groups and found something on this topic, but no solution:...
7
9440
by: Brett Robichaud | last post by:
I'm trying to decide on the right approach for communication between the UI and a worker thread in a WinForms app. I am very familiar with threads in the unmanaged C++ world and in the past have used WM_USER based messages to communicate status from the worker thread back to the UI thread. What is the right way to do this in .Net? Are asynchronous delegates the way to go, or is there a better (or just different) approach I should...
2
2147
by: Peter Wone | last post by:
I've written a class which does some long running background processing and returns multiple results via events. The class has an Execute() method which creates a thread and runs an internal method _execute() on it. When events fire they are running on the worker thread. To use this class from a form with event handlers that manipulate the UI, you have to write this public void MyForm_DocumentReady(object Sender, DocumentReadyEventArgs...
5
2388
by: Dan Tallent | last post by:
I am trying to learn how to create an application that uses worker threads to prevent the UI from freezing up. My question is: Is the following code considered "thread safe"? If not, what am I doing wrong? Thanks Dan -------------------------------------------------------- I have a form with this code:
2
1554
by: Jerry Spence1 | last post by:
One way of passing data to a thread is to encapsulate the thread inside a class. However, I can't refer to my main form objects from within the class/thread as it says "Reference to a non-shared member requires an Object reference". How do I refer to items such as Textbox1.text etc on my main form? -Jerry
12
1245
by: Peter Proost | last post by:
Hi group, I have been doing some reading on threading and updating the ui from a worker thread and I made this sample which works but I was wondering if it's the ok way to do it? Can I improve something? What's the best practise for updating multiple controls on my form for example 5 labels or so, just keep passing them to the constructor? Greetz, Peter
0
1065
by: samuel84 | last post by:
Hi All, I have a SynchEngine Class which has a Synch() method and throws a StatusChange event at various stages of sync, i would like to run this sync process in a new thread as i need to periodically update my progress bar and prevent freeze up of my forum. I basically want to know how to subscribe to events that happen inside a thread. the code i have used is and the error i got in the engine_StatusChanged method is "Control.Invoke...
8
6498
by: =?Utf-8?B?T2xpdmVy?= | last post by:
Hey there, im quite new to C# GUI-Framework and got a question now. In Java its no problem todo cross-over Thread-calls. So i can change something in a Window from another thread. It seems C# lacks of this ability. I got a normal GUI and want to start a thread where this gui is also changes from. I made this working before with delegates. Ok so far...this would be a way to solve the issue. But it looks like much work if i have todo...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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
2
1733
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.