Is there a concept of session management in Winforms applications? [closed]
开发者_开发技巧
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 months ago.
Improve this questionToday I was asked why we cannot implement state management in Winforms applications like we do in web applications, and I did not know the answer.
Can someone explain why we cannot, or if we can, explain how it works at a high level?
[...] why we cannot implement state management in Winforms [...]
This is an incorrect statement. In fact, we implement session management in every Winforms application, and we are so habitual about doing it that we don't even realise we are doing it.
The very nature of a desktop application is that all the state information you need is available in process memory, and it remains available as long as your application is running.
For example, it you set the value of a string variable to "Hello World", it will retain its value as long as that variable is accessible. Unlike web applications, you don't have to do anything explicitly to retain it. So the correct question might be
Why don't we need to implement session management in a WinForms application?
although I would be stumped by the obviousness of answer.
We can implement state management in Winforms.
Assume you need to access a Winforms control value in another Winforms application by clicking a button on the first form. You can access them by:
- declaring public class members and auto implemented properties in the second form.
- Set the values of the second form's class members in the first form's
button_click
event - After step 2, run the code you want to run on button click.
So the class and its members can be used in achieving state management in Winforms application.
精彩评论