Let´s say I have a class like this:
class Test{
private string status;
public Test(){
//Do some processing. After processing is done assign
status = "processdone_uniqueidhere";
}
}
Now, in my asp.net application I need to periodically check status using a timer for a value when the processing is done.
Basically, I can store the reference of the class "Test" in session such as:
Test t = new Test();
Session["uniquesession"] = (Test)t;
This was, in the timer, I can retrieve the instance of the class from the session and check for the value of status:
Test t = (Test)Session["uniquesession"];
string value = t.status;
I´m not able to store the reference in a ViewState even if I declare the class as [Serializable]. Not sure why. Works with session though.
The other method is to declare the class as static and declare the variable status as static and public and check the value like this:
string value = Test.status;
Which way is most stable and which way is bad practice?