I have two controller methods:
public string Nothing()
{
if (Session["done"] == null)
{
Session["done"] = false;
}
while (!bool.Parse(Session["done"].ToString()))
{
System.Threading.Thread.Sleep(1000);
}
return "done";
}
public string AnotherMethod()
{
Session["done"] = true;
return "hello";
}
The first method is called and the second method is intended to stop the execution of the first method. However when I watch the variables during debugging The Nothing method never stop executing and the Session["done"] value is always false, even after calling the other controller method AnotherMethod()
Why is this happening and how can I stop the execution of the Nothing method with a variable change in AnotherMethod?
In ASP .NET, each request gets its own copy of session state meaning The
Sessionis thread safe.You will need other way to achieve what you are trying to do, static variable sounds suitable.
Read this MSDN article
Example: