Hi,
Im familiar with c,c++ etc, and Ive spent a week trying to write my
first app in c#
it works reasonably well, but im having difficulty getting to grips with
inter thread signalling etc.
I have read all about delegates, event handlers, Invoke methods etc, however
they all seem to have undesribale side effects as I have tried them.
The hardest part of the aplication is on exit, well I gues I could just
ignore it and let it fail ungracefully,
but the usb Bluetooth com device doesnt like that very much, it takes ages
before it can be opened again.
I have a seperate thread wich reads from the com port and wich needs to be
as realtime as possible.
it also needs to send data to the UI. it can also get stuck for some time in
the open,read etc, and the UI thread must wait before it exits the app, if
it waits just as the com thread is about to use invoke to update the UI it
gets deadlocked.
using BeginInvoke would be too heavy on the thread pool as the data can be
quite fast.
putting the data in a list protected by lock would be ok,
but then the problem is how to get the UI thread to look,
polling would be either too slow or use up to much cpu time,
a secondary thread to wait for the list to become non empty wich could then
use invoke to update the UI
this would work but seems to be getting rather complicated.
idealy I just want to send an event to the main message pump of the UI
thread wich is how it would be done
in the lower level languages
I have tried the OnEvent method but this still just runs the event handler
in the current thread.
Is there some equavalent in c# or something that I have overlooked ?
thanks
Colin =^.^=
Im familiar with c,c++ etc, and Ive spent a week trying to write my
first app in c#
it works reasonably well, but im having difficulty getting to grips with
inter thread signalling etc.
I have read all about delegates, event handlers, Invoke methods etc, however
they all seem to have undesribale side effects as I have tried them.
The hardest part of the aplication is on exit, well I gues I could just
ignore it and let it fail ungracefully,
but the usb Bluetooth com device doesnt like that very much, it takes ages
before it can be opened again.
I have a seperate thread wich reads from the com port and wich needs to be
as realtime as possible.
it also needs to send data to the UI. it can also get stuck for some time in
the open,read etc, and the UI thread must wait before it exits the app, if
it waits just as the com thread is about to use invoke to update the UI it
gets deadlocked.
using BeginInvoke would be too heavy on the thread pool as the data can be
quite fast.
putting the data in a list protected by lock would be ok,
but then the problem is how to get the UI thread to look,
polling would be either too slow or use up to much cpu time,
a secondary thread to wait for the list to become non empty wich could then
use invoke to update the UI
this would work but seems to be getting rather complicated.
idealy I just want to send an event to the main message pump of the UI
thread wich is how it would be done
in the lower level languages
I have tried the OnEvent method but this still just runs the event handler
in the current thread.
Is there some equavalent in c# or something that I have overlooked ?
thanks
Colin =^.^=
Comment