Hi all,
I'm currently building some stuff into a web application and the application uses session state to 'remember' a user. It's an existing application, so I can't change that.
Now in the user object I want to update a property and all is well.
However, on one occassion I want to set it from a worker thread.
So, in my Controller I have something like this:
this.Session["user"] = myUser;
var user = (User)this.Session["user"];
user.SomeProperty = myValue;
var user = (User)this.Session["user"];
var myValue = user.SomeProperty;
That works really great!
Now in another Controller I have the following:
var user = (User)this.Session["user"];
Task.Factory.StartNew(() =>
{
user.SomeProperty = myValue;
});
var user = (User)this.Session["user"];
var myValue = user.SomeProperty;
So now I read that storing a value in the session is thread-dependent. I tried running a follow-up task and force it to run on the main thread, but the main thread is, of course, gone.
So is there any way to update this variable into my session on the worker thread?
Thanks.