Today 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?
Today 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:
button_click
eventSo the class and its members can be used in achieving state management in Winforms application.