0

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Developer
  • 8,390
  • 41
  • 129
  • 238

2 Answers2

5

[...] 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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Hemant
  • 19,486
  • 24
  • 91
  • 127
  • So as per your answer as windows application is statefull there is no need to use state management right – Developer Mar 22 '11 at 09:28
  • Yes you can say that. Just put the word "explicit" to make it better (...there is no need to use **explicit** state management) – Hemant Mar 22 '11 at 09:37
0

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:

  1. declaring public class members and auto implemented properties in the second form.
  2. Set the values of the second form's class members in the first form's button_click event
  3. 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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Anji
  • 301
  • 3
  • 3