简体   繁体   English

如何在C#.net中创建一个弹出窗口

[英]how to create a popup window in C#.net

I have two different applications on different system.If a button pressed in one application i keep its record in Database and according to the record I want to popup a window in second application that notifying that Button is pressed in first application. 我在不同的系统上有两个不同的应用程序。如果在一个应用程序中按下一个按钮,我会将其记录保存在数据库中,然后根据记录我想在第二个应用程序中弹出一个窗口,通知该按钮在第一个应用程序中被按下。

How could I do this? 我该怎么办? Is it feasible? 可行吗

Since you are storing a record in the database, you can poll the database from second application and take the action based on the state. 由于您将记录存储在数据库中,因此可以从第二个应用程序轮询数据库,然后根据状态执行操作。 Once the request has been addressed, you can mark the record in the database. 解决了请求后,您可以在数据库中标记记录。

You said different systems (ie computers). 您说过不同的系统(即计算机)。 right? 对?
In that case you would have to send some sort of message to the other application to initiate a popup. 在这种情况下,您将必须向其他应用程序发送某种消息以启动弹出窗口。

Is the Database you are storing the value accessible by both Computers ? 您正在存储的数据库是否可以由两台计算机访问?
In that case if a little delay (few seconds) is acceptable between pressing a button in an app on one computer and the popup on the other, you could also use some sort of polling. 在这种情况下,如果在一台计算机上按一个应用程序中的按钮与另一台计算机上的弹出窗口之间有一点延迟(几秒钟)是可以接受的,那么您也可以使用某种轮询。 So the other system where the popup would show, can check the database at regular intervals (say every 10 seconds) for the record that is set by the Button press and if present then show the popup. 因此,将显示弹出窗口的另一个系统可以定期检查数据库(例如,每10秒)以查找由Button按下设置的记录,如果存在,则显示弹出窗口。

But if such a delay is not acceptable, then you would need to use some networking between the two applications. 但是,如果这样的延迟是不可接受的,那么您将需要在两个应用程序之间使用一些网络。 So a message can be sent directly to the popup generating application from the button one. 因此,可以将消息从按钮之一直接发送到弹出窗口生成应用程序。

Update 更新资料
Yes you will need a continuously running exe on the other (popup) system for either of solutions, be it database polling or networking. 是的,对于任何一种解决方案,无论是数据库轮询还是网络连接,您都需要在另一个(弹出)系统上持续运行的exe。

For Database Polling : 对于数据库轮询:

  • Simply create a windows application. 只需创建一个Windows应用程序。
  • Add a timer object to it with an interval of as many milliseconds you want between polls (for 10 seconds set it to 10000) 向其添加一个计时器对象,两次轮询之间的间隔时间为您想要的毫秒数(在10秒钟内将其设置为10000)
  • Then write database retrieval code in the Tick event Handler for the timer control. 然后在Tick事件处理程序中为计时器控件编写数据库检索代码。

For Networking : Take a look at following question - networking in .net/C# 对于网络 :看看以下问题-.net / C#中的网络

If you're using SQL Server as your database you may be able to use SQL Server Query Notifications 如果您使用SQL Server作为数据库,则可以使用SQL Server查询通知

This discussion is similar... Notification about Database Change 这个讨论是类似的... 有关数据库更改的通知

Instead of using polling from the 2nd app, you can be notified when the table changes. 表格更改时,您会收到通知,而不是使用第二个应用程序中的轮询。 You can use a class called SqlDependency for this. 您可以为此使用一个名为SqlDependency的类。 A good example can be seen on codeproject . codeproject上可以看到一个很好的例子。 In fact, the example sounds very close to what you're looking for. 实际上,该示例听起来与您要查找的非常接近。

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

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