简体   繁体   English

我应该如何编写C#Windows窗体应用程序的事件处理程序?

[英]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. 我目前正在开发一个C#Windows窗体应用程序,我打算让它与服务器进行交互。 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. 服务器将从我开发的移动应用程序接收发布,并且每当收到发布时,我的Windows窗体应用程序应该得到通知并给我通知。

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. 一旦我的服务器收到消息,我的Windows窗体应用程序应显示一个新通知,显示收到的消息内容。

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? 我知道如何编写我的C#应用​​程序以接收上述信息?

You can implement a WCF Service inside your server. 您可以在服务器中实现WCF服务。 You Windows Form application can be your WCF Service client. 您的Windows窗体应用程序可以是您的WCF服务客户端。

What you probably want is a Duplex Service 你可能想要的是双工服务

They way this would work is 他们这样做的方式是

  1. WCF Service in running on your server WCF服务在您的服务器上运行
  2. Windows Form connects to your server WCF service using Duplex Contract Windows窗体使用“双工合同”连接到服务器WCF服务
  3. Mobile app posts to server 移动应用程序发布到服务器
  4. WCF Service knows about it and using the call back channel notifies the WCF Client WCF服务知道它并使用回叫信道通知WCF客户端
  5. Your Form Application aka WCF Client updates UI with this new message received 您的表单应用程序即WCF客户端使用此新消息更新UI

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. 作为@parapura rajkumar答案的替代方案,您还可以研究Message Queue体系结构 ,其中从移动应用程序发回的消息对服务器和Windows客户端都是可见的。

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... 也许更重一点,但肯定值得考虑,特别是如果你怀疑应用程序可能需要在未来增加复杂性...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该为Windows应用程序使用哪个事件处理程序? - Which Event handler should i use for my windows application? C# - SignalR如何删除我的事件处理程序 - C# - SignalR How can I remove my event handler 为什么此代码(可能是事件处理程序)在我的 c# windows 服务中导致 memory 泄漏? - Why is this code (possibly event handler) causing a memory leak in my c# windows service? 我的C#Windows表单应用程序是空白的? - My C# Windows Form Application is blank? 我的c#windows表单应用程序和azure - my c# windows form application and azure 如何使用c#在我的Windows窗体应用程序中嵌入vlc - How to embed vlc in my windows form application with c# c#如何将pdf文件包含到我的Windows窗体应用程序中 - c# how to inclued a pdf file to my windows form application 如何自动最小化Windows窗体应用程序(C#)? - How to automatically minimize my Windows Form Application (C#)? C#:如何在Windows应用程序中的Win窗体上自由移动控件? - C#: How can I move my controls on a win form in windows application freely? 如何将 VBA 宏转换为 C# 以在 Windows 窗体应用程序中使用? - How do I convert my VBA macro to C# to use in windows form application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM