1

We are trying to develop a WCF service for executing a long running task. The method implementing the long running task spawns a new task and immediately returns to the client(which in our case is an .aspx page) if the task has been successfully queued. The service is running on its own application pool with no recycling and single InstanceContextMode.

WCF Service

[OperationContract]
public bool testThreadAbortException()
{           
    Task.Factory.StartNew
    (
        () =>
        {                         
            try
            {
                //long operation
                int i = 0;
                while (i < 250)
                {         
                    int j = 0;
                    while (j < 2000000) j++;
                    i++;
                }
                ThreadState state = Thread.CurrentThread.ThreadState;
                string  dummy = "finished ";
            }
            catch(Exception exception)
            {
                ThreadState state = Thread.CurrentThread.ThreadState;
                string msg = exception.Message;
                Exception inner = exception.InnerException;                        
            }
        }
   );

   return true;                       
}

Client

protected void btnRun_Click(object sender, EventArgs e)
{
    _default.IISHOST_ETLSchedulerServiceReference.ETLSchedulerServiceClient client = new _default.IISHOST_ETLSchedulerServiceReference.ETLSchedulerServiceClient();
    bool ret = client.testThreadAbortException();
}

Now the problem is that while the testThreadAbortException method is being executed i catch the Thread was being aborted exception ( this always happends after the client has exited the event handler method ). The weird thing is that this exception is only thrown the first time (ie if i press the run button again the code executes fine). I have to restart my local IIS to replicate the error again.

  1. Does anyone have a clue know why this happens??
  2. Is there a better way to implement what i am trying to archive besides switching to a windows service??
AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
  • Are you doing anything to cause the IIS worker to be recycled? This sounds like appdomain unloading. There is no other reason this thread pool task would be aborted. – usr Feb 16 '16 at 14:30
  • No i don' t think so. Could the client recycle options affect in any way the appPool of the service ?? – Savvas Konstantinou Feb 17 '16 at 08:09
  • Ok @usr you were right. After further investigation it seems that the appdomain on which the wcf service is running is unloading. The actual reason is: "Change in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\iishost_wcf_etlschedulerservice\fad2fd98\ca78657a\hash\hash.web HostingEnvironment initiated shutdown HostingEnvironment caused shutdown ". Any more comments on this would be deeply appreciated... – Savvas Konstantinou Feb 17 '16 at 15:11
  • Looks like something writes to the app causing it to recycle. That's likely a bug in your code. You can catch the offending processing using procmon.exe – usr Feb 17 '16 at 15:22

1 Answers1

0

As it seems its Mcafee antivirus after all that is accessing the hash.web file. Confirmed with process monitor. Go figure..... For more info check this post. Issue similar to mine.

Community
  • 1
  • 1