473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 1912

"Paul" <pm*******@hotmail.comwrote in message
news:e2**************@TK2MSFTNGP03.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
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...
8
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...
7
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...
2
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...
5
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...
2
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...
12
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...
0
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...
8
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#...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.