Communication between a thread and a form.

  • Thread starter Thread starter Fabrice HOEPPE
  • Start date Start date
F

Fabrice HOEPPE

Hi,

I want to fire C# events from a thread to a windows form.
One way to do it, it's to call BeginInvoke, Invoke,
EndInvoke methods of the windows form control from the
thread. However, this mechanism uses the serialization of
data from the thread to the form. We can read into the
msdn that this mechanism requires a lot of resources
system. I need to improve this mechanism for a real time
application which uses a low resource system and which
must be run fastest. I have worked with an another team
which have been developped this kind of application but in
Java. I was very surprised of its performance. In my case,
it is the only one point that I must improve if I want to
be much competitive than Java. Do you have any ideas to
improve the communication between a thread to a no thread-
safe windows form or an another way to communicate from a
thread to a form into a thread safe context?

Fabrice
 
I'm not sure if the parameters for an intra-AppDomian call are serialized,
but assuming they are, you can avoid the hit by using global variable
instead of parameters - maybe pass an integer representing the index of
large parameters in a globally accessible collection. As long as the
objects that would normally be passed as parameters are thread-safe, you
won't have any problems with this approach.

Nick Wienholt, MVP
Maximizing .NET Performance
http://www.apress.com/book/bookDisplay.html?bID=217
Sydney Deep .NET User Group www.sdnug.org
 
The actual cost of getting onto the UI thread is reasonably fixed. The
thread model of Windows requires the marshalling in the method you include,
and there isn't a lot you can do to bypass it. Posting a custom message to
the windows form message loop is pretty cheap, and would be an option I'd
try.

Nick
 
Back
Top