简体   繁体   中英

How should I code my event handler for my C# Windows Form Application?

I am currently developing a C# Windows Form Application that I intend to let it interact with a server. The server will receive posting from a mobile application that I have developed and whenever a posting is received, my Windows Form Application should be notified and give me a notification.

Eg My mobile application sends an message over to my server. Once my server receives the message, my windows form application should display a new notification showing the content of the message received.

The above scenario is just a example of what I intend to do with the whole thing. Any idea how should I code my C# application in order to receive the information as stated above?

You can implement a WCF Service inside your server. You Windows Form application can be your WCF Service client.

What you probably want is a Duplex Service

They way this would work is

  1. WCF Service in running on your server
  2. Windows Form connects to your server WCF service using Duplex Contract
  3. Mobile app posts to server
  4. WCF Service knows about it and using the call back channel notifies the WCF Client
  5. Your Form Application aka WCF Client updates UI with this new message received

As an alternative to the answer @parapura rajkumar, you could also investigate a Message Queue architecture , where the messages posted back from the mobile app are visible to both the server and the Windows client.

Perhaps a little more heavy-weight but certainly worth consideration, especially if you suspect the application may need to grow in complexity in the future...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM