Say that I have
public static class M
{
public static string Concat(string a, string b)
{
return N.AddOne(a, b);
}
public static string Concat2(string a, string b)
{
return SomeThreadSafeMethod(a, b);
}
}
public static class N
{
public static string AddOne(string a, string b)
{
return a+b+1;
}
}
Is M.Concat a threadsafe operation?
What about M.Concat2? Would it be possible for SomeThreadSafeMethod get call with a different a or b in a multithread context?
The reason I ask this question is I want to have a better understanding of how C# deal with threading, especially
for the M.Concat2 case.
Secondly I am working with Asp.net MVC and I am concern that when I call Html.ActionLink or RouteLink with a route with variable
something simple such as
Html.ActionLink("Test", "Index", "Test", new { Model.Id, Model.State})
When multiple users hitting the same page, each of them will get a different State. If it’s not threadsafe then I might get back a different route than intended.
The
Concatmethod is absolutely thread safe because it doesn’t set any variable. TheConcat2is also thread safe because of the way you are calling it. You only passModelproperties and and you get a different model instance every time. The only issue might be in theSomeThreadSafeMethodmethod if it sets static variables without locking.