0

I have a Windows Server 2008 R2 IIS 7 instance running .ASP.NET WebForms .NET 4.0 code. In a postback there is a thread spawn that runs a long-running process.

The below code does not work under IIS7. It works fine locally under Cassini and on another Windows Server 2003 IIS6 instance we have available.

var t = Task.Factory.StartNew(() => ProcessWorkItem(wid));
var ex = t.Exception;
Log(string.Format("Spawned background task to wid={5}: id={1} status={4} isfaulted={3} iscompleted={2} ex={0}",
            ex == null ? "no exception" : ex.ToString(),
            t.Id,
            t.IsCompleted,
            t.IsFaulted,
            t.Status,
            wid));

This logs "no exception" and "isfaulted=false" and "iscompleted=true" regardless of server.

However, there is also a log statement inside the ProcessWorkItem, which is never hit on IIS7, though it is hit just fine on IIS6 or Cassini local dev server.

Any idea why that would be?

Scott Stafford
  • 43,764
  • 28
  • 129
  • 177
  • Where is the log file? IIS may not have the privilege to write to the local disk. – Matt Dec 18 '14 at 20:43
  • It actually logs to the system eventlog. The user running IIS has access to the event log. – Scott Stafford Dec 18 '14 at 20:45
  • ProcessWorkItem was run. It just has a bug. – usr Dec 18 '14 at 22:16
  • @usr: I thought that too, but I can't substantiate it in any way. The first thing in the action is Log(...) and I never see that. Maybe I can try throwing an exception instead... see what that does... – Scott Stafford Dec 19 '14 at 14:06
  • 1
    I had similar issue, once deployed, it method was not getting called. Parameters to method turned out to be the issue. I encapsulated parameters into internal class & it started working. – SamJackSon May 19 '15 at 02:06
  • @SamJackSon: Can you provide an example of what you mean? – Scott Stafford May 21 '15 at 14:53
  • Please take a look at this thread: http://stackoverflow.com/questions/12665536/prevent-iis-from-killing-a-task-before-it-ends – jonatasmello Dec 16 '16 at 21:42

0 Answers0