Hi.
I'm using an ApplicationContext to keep my Form application alive without having a specific main form.
At the same time I have a second thread running network operations.
I want to know how to schedule updates to the UI from my second thread.
I can't call Invoke() because there is no main Form to call the function on - and the ApplicationContext does not supply this function.
Any help would be good. Thanks,
justin
---------- Post added at 05:39 AM ---------- Previous post was at 05:11 AM ----------
In case anyone else wants to know the answer, it is this wise:
Save the SynchronizationContext of the UI Thread and then use that context object to send() calls to the ui thread.
4 replies to this topic
#1
Posted 22 August 2011 - 04:39 AM
|
|
|
#2
Posted 22 August 2011 - 07:13 AM
I would have handled this by having a seperate data object with a Dirty event that the form subscribed to. The network updates the object, which automatically triggers the dirty event which the UI then handles. That way my network code isn't coupled with the UI and I can change either without affecting the other.
#3
Posted 22 August 2011 - 07:28 AM
Are you talking about a specific data object class provided by windows forms?
I'm not very familiar with them so my only question is how you go from the dirty event, to the UI-safe thread.
Is the dirty event automatically triggered on that thread?
As for coding clarity i wrote a bridge class linking the UI with the underlying udp networking. but ill be sure to learn about the data class if its available.
I'm not very familiar with them so my only question is how you go from the dirty event, to the UI-safe thread.
Is the dirty event automatically triggered on that thread?
As for coding clarity i wrote a bridge class linking the UI with the underlying udp networking. but ill be sure to learn about the data class if its available.
#4
Posted 22 August 2011 - 08:07 AM
No, it's not provided by the form. You'd create your own class with properties and a single event Dirty. The properties would set whatever values then trigger the Dirty event. The UI subscribes to the Dirty event (like any other event) and when it fires pulls values from the properties of that class and sets the various UI elements based on those values. The network just sets the properties as the values it gets change.
#5
Posted 22 August 2011 - 08:10 AM
I guess my question would be, if the Network is setting the Dirty event from the network thread, wouldnt the dirty event handlers all be called on the network thread, and hence be UI unsafe?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









