Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session for windows forms application in C#

Is there a session for Windows based applications for C# in order to record the details of log in in and log out for multiple users?

I tried to use declaring static variables, but it is not the same as a session.

like image 958
Tsuna Sawada Avatar asked Jan 30 '13 08:01

Tsuna Sawada


2 Answers

There is no concept of session variables in Windows Forms. You can do:

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;
like image 71
sajanyamaha Avatar answered Sep 20 '22 16:09

sajanyamaha


No, there are no session variables in a normal Windows application (the way there is in a web application). If you need logging for a Windows application I agree with the previously written comment to use some logging framework like log4net, NLog or something like that. Even using the Eventlogs can be an option, but I don't recommend it.

like image 35
Sandman Avatar answered Sep 17 '22 16:09

Sandman