I have a task that is not important ; it should be run once in while if the website is used.
So I tried this approach : https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/
The task could be long so I want it to be asynchronous… so that the navigation is not stopped by the background task.
The thing I don’t understand is that when I start debugging (attach to process w3wp.exe) I can’t navigate on the site anymore until I stop debugging?
Here is the code (ResourceService being a WCF service hosted on ISS in the same project) :
private void CacheItemRemoved(string taskName, object seconds, CacheItemRemovedReason r)
{
switch (taskName)
{
case MedianamikTasks.UpdateResources:
if (Config.EnableAutoResourceUpdate)
{
ThreadStart threadStart = ResourceService.UpdateResources;
var thread = new Thread(threadStart) {IsBackground = true};
thread.Start();
//Do not use... : http://csharpfeeds.com/post/5415/Dont_use_the_ThreadPool_in_ASP.NET.aspx
//ThreadPool.QueueUserWorkItem(x => ResourceService.UpdateResources());
}
break;
}
AddTask(taskName, Convert.ToInt32(seconds));
}
Just a guess, but do you have a breakpoint set? As soon as you hit a breakpoint the execution in the w3wp processes will stop at that point, thus you won’t be able to ‘navigate’ around the site.