Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that the class you are trying to activate is probably attempting to use HttpContext.Current, which doesn't exist on the background thread as it is kept in thread-local storage.</p> <p>I assume you are doing something like this:</p> <pre><code> public void StartBackgroundRequest() { var thread = new Thread(StartMethod); thread.Start(); } private void StartMethod() { //bunch of stuff var request = NewRequest(className); // exception gets throw here } </code></pre> <p>You need to change this so that it captures the HttpContext on the request thread and sets it on your background thread before activating the type:</p> <pre><code> public void StartBackgroundRequest() { var thread = new Thread(StartMethod); thread.Start(HttpContext.Current); } private void StartMethod(object state) { HttpContext.Current = (HttpContext)state; //bunch of stuff var request = NewRequest(className); // exception gets throw here } </code></pre> <p>I should note that there may be additional nuances to the implementation of the component you are activating that may mean it doesn't play nice in a multi-threaded environment, I have no idea.</p> <p>It's also noteworthy that the IIS/ASP.NET threading/process model can be a bit complex, so you may or may not want to actually do this on a background thread depending on your requirements. For example, IIS can recycle the process when there are no more outstanding requests, but your background thread might still be running. If I have a need to run background tasks that need to run to completion, I will usually split that functionality into a separate windows service or similar and proxy those tasks to it so that I have better control over the process and threads.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload