title: c# thread safety when referencing static properties on other classes
body: <p>I have a method to generate fully qualified URLs that I wrote which I would like to have as static so its easy to call from models as needed.</p>
  
  <p>I'm still having problems however with being able to decide if its thread safe or not. </p>
  
  <p>Here is the code.</p>
  
  <pre><code>    public string GenerateURLFromModel(string action, string controller)
      {
          HttpContextWrapper wrapper = new HttpContextWrapper(HttpContext.Current);
          Uri url = HttpContext.Current.Request.Url;
          UrlHelper urlHelper = new UrlHelper(new RequestContext(wrapper, RouteTable.Routes.GetRouteData(wrapper)));
  
          return url.AbsoluteUri.Replace(url.PathAndQuery, urlHelper.Action(action, controller));
      }
  </code></pre>
  
  <p><b>What I know already is:</b></p>
  
  <p>1) The two strings passed in will be thread safe since they are immutable reference types.</p>
  
  <p>2) All objects instantiated within a static method can be considered thread safe since they exist only on the stack for that specific thread.</p>
  
  <p><b>What I'm unsure of is:</b></p>
  
  <p>1) How does the use of HttpContext.Current and RouteTable.Routes play in this method? They are both static properties that I'm passing into the constructors.</p>
  
  <p><b>My questions are:</b></p>
  
  <p>1) What are the implications of using these static properties?</p>
  
  <p>2) Does the rest of my understanding of the safeness of this method ring true?</p>
  
  <p>3) What rules can I keep in mind in the future to help determine thread safeness in situations like this?</p>