Forum Xamarin.Mac

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How could I synchronise my cocoa application?

I have a client-server c# application built as cocoa application on the client side. My problem is described by the following example: a message is sent to the server that something is needed. My client is async and when receives a message checks the message type. Depending on the message type, it should do something client side. For example, if client requests to log in, the server will send him back null (if he introduced wrong data) or an User ( which is a model, a class). The message is received by the client, and he should either put something in a NSTextField(a message because the introduced data doesn't exist) either to show a new window for example. Instead of taking this information --null or user-- back to NSViewController, I have a class, Handler, which has a method and depending on the message type should do NSViewController.showSomethingInNsTextifeld or pop up a new window. Now, I know static methods would have been bad practice and anyways I couldn't define static methods for this, so I made an interface, IController. Each NSViewController implements this IController interface. So now in my Handler I should only have the interface as instance variable, and in each NSViewController I have a new instance(this), where this will be the interface. Everything should work fine by now, except that my interface is always left behind. By this I mean, it is always in a different NSViewController and showing windows/labels in the wrong one. I would appreciate any help since I have this problem for over a week now. Thank you in advance and sorry for the long post..

Answers

  • GeoffHartGeoffHart Member

    For better or worse, I solved a similar problem where we have background asynchronous workers triggering updates in various tabs in our GUI hosted in different NSViewControllers using static events.

    So each type of action that needs to update the GUI has a static event, and the NSViewControllers that care about it subscriber to the static event. I think this is an ok design because the events can happen anytime and all live for the duration the application is running, so it doesn't really introduce any overhead.

    This solved a lot of problems for us with trying to figure out which NSViewController to send the items to, having the NSViewControllers inherit or implement interfaces, and having to distribute references like confetti all of the code to connect things together.

Sign In or Register to comment.