I’m using an MVC pattern in winforms application. I need to call remote service asynchronously. So On some event in View I invoke corresponding Presenter method. In Presenter I call BeginInvoke method of service. But to View must be updated only in Main Thread. I could actualy point CallBack to some function in View, and update it`s controls state, but this conflicts with MVP pattern – View must not be responsible for data it carries. This callback function must be in Presenter. But how then invoke View in Main Thread?
Share
Put the callback function in the presenter. Have the presenter call whatever update function on the view is required/have the view observe the presenter’s state and handle the ‘completed’ event. In the view’s function, if the view is implemented by a windows Form, test the
InvokeRequiredproperty to see if the call has come in on the windows thread. If it hasn’t, then useInvoketo invoke it instead.