Reputation: 3969
I have a WinForms application that is the UI layer running over the logic layers.
My application is a client-server IM program. When the internal program accepts an incoming connection request I'd like the UI to be updated by a simple button text change. The issue is the separation of concerns, decoupling.
One way to do this would be to expose an internal boolean that is changed by the logic layer when it has processed a request and is constantly checked by the UI on its own thread.
This doesn't seem like the best way to me, I assume there are much better built in ways for doing this?
Upvotes: 1
Views: 54
Reputation: 4156
Expose a delegate in the "internal" program:
public Action<bool> RequestProcessed { get; set; }
Somewhere in your internal code when a request is processed
if(RequestProcessed != null)
RequestProcessed(true);
In the gui you create a method
public void SomethingHappend(bool processed) {
// Do gui stuff
if(processed) {
}
else {
}
}
In the gui, subscribe like this:
innerInstance.RequestProcessed = SomethingHappened;
Upvotes: 1