用户登录会话时运行的程序。 [英] Program that runs when a user login to a session.
问题描述
大家好,
我想启动一个进程,将一些缓存信息(角色和应用程序详细信息保存在内存中)直到该会话结束,而不是每次访问服务器。我怎么能在Windows (Windows7 / xp,Windows 2000等)?可能会看到单一解决方案。
我们可以在每次登录/登录会话中启动Windows服务吗?
谢谢
Boby Jose
会话
你需要使用全局变量或静态类。
参考 - c#中的窗体应用程序会话 [ ^ ]。
< blockquote class =FQ>Quote:Windows窗体中没有Session变量的概念。你可以做的是:
创建一个静态类,其中包含用户名和密码以及整个应用程序所需的任何其他变量。
在您的情况下,它将类似于:
public static 类 LoginInfo
{
public static string UserID;
}
现在您只需从代码中的任何位置访问UserID:
MessageBox .Show(LogInfo.UserID);
或者在登录后设置值,例如
LogInfo.UserID = TextBox1.Text;
缓存
查看以下内容。
1. [MSDN]缓存应用程序块 [ ^ ]。
2. 在WinForms应用程序中使用缓存 [ ^ ]
Hi All,
I want to start a process that keeps some cache info (roles and apps details in memory) till end of that session rather each and every times access server. How can I do in windows (Windows7/xp, windows 2000 etc)? Likely to see a single solution.
Can we start "windows service" in each logon/login session"?
thanks
Boby Jose
Session
You need to use Global Variables or Static Classes.
Refer - Session for windows forms application in c#[^].
Quote:There is no concept of Session variables in windows forms. What you can do is:
Create a Static class that holds the User name and password and any other variables needed across the application .
In your case it would be something like:
public static class LoginInfo { public static string UserID; }
Now you can access the UserID simply from anywhere in your code:
MessageBox.Show(LogInfo.UserID);
Or set the values after login like
LogInfo.UserID=TextBox1.Text;
Cache
Go through the below ones.
1. [MSDN] The Caching Application Block[^].
2. Using Cache in Your WinForms Applications[^]
这篇关于用户登录会话时运行的程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!