C#检查我的申请过程是否已终止 [英] C# check if my application process is terminated

查看:53
本文介绍了C#检查我的申请过程是否已终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,程序员!我有一个连接到SQL数据库的应用程序,您可以在其中登录,注销.用户登录时,程序将"1"发送到SQL字段"IsUserOnline",而注销时则发送"0".我的观点是,例如,当用户停止应用程序进程时,数据库中的值仍将为"1"-即使关闭程序,也将显示当前用户在线.

有什么办法可以终止应用程序进程以执行一些代码以防止该错误发生?

Hello, programmers! I have an application that connects to SQL database where you can login, logout. When an user logges in, the program sends ''1'' to SQL field ''IsUserOnline'' and when logout - ''0''. My point is when for example the user stops the application process, the value in database will be still ''1'' - even if the program is closed, it will show that the current user is online.

Is there any way before the app process is terminated to execute some code to prevent that bug happening? Thanks a lot in advance!

推荐答案

假设您已经拥有应用程序的源代码,并且可以访问SQL数据库(并且具有足够的权限),您可以:

0)修改您的应用程序,以便每隔几分钟就向sql数据库发送一次更新.它所要做的只是一个存储的过程,该过程接受用户ID,并更新与用户登录状态记录关联的时间.只要用户登录,一切都会很酷.

1)当用户注销时,让应用程序将适当的指示符发送到数据库.

2)如果用户超时(时间太长而没有在应用程序中进行任何活动,请让应用程序注销用户(然后它将注销通知发送到数据库

3)将作业放入数据库,该作业每X分钟运行一次,以扫描非活动登录,如果找到,则会自动将非活动用户设置为注销.
Assuming you have the source code to the app, and access (and sufficient permissions) to the SQL database, you can:

0) Modify your app to send an update to the sql database every so many minutes. All it has to be is a stored proc that accepts the user ID, and that updates the time associated with the users login status record. As long as the user is logged in, everything is cool.

1) When the user logs out, have the app send the appropriate indicator to the database.

2) If the user times out (goes too long without any activity in the app, have the app log the user off (and it will then to the logout notification to the database

3) Put a job in the database that runs every X minutes that scans for inactive logins, and if found, automatically sets the inactive users to logged out.


这篇关于C#检查我的申请过程是否已终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆