简体   繁体   中英

“Thread was being aborted ” on WCF service

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??

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM