简体   繁体   English

WCF服务上的“线程被中止”

[英]“Thread was being aborted ” on WCF service

We are trying to develop a WCF service for executing a long running task. 我们正在尝试开发WCF服务来执行长时间运行的任务。 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. 如果任务已成功排队,则实现长时间运行的任务的方法将产生一个新任务,并立即返回到客户端(在本例中为.aspx页)。 The service is running on its own application pool with no recycling and single InstanceContextMode. 该服务在自己的应用程序池上运行,没有回收并且只有一个InstanceContextMode。

WCF Service WCF服务

[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 ). 现在的问题是,在执行testThreadAbortException方法时,我捕获到线程被异常中止(这总是在客户端退出事件处理程序方法之后发生)。 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. 我必须重新启动本地IIS才能再次复制该错误。

  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?? 除了切换到Windows服务之外,还有没有更好的方法来实现我要归档的内容?

As it seems its Mcafee antivirus after all that is accessing the hash.web file. 看起来它的Mcafee防病毒程序毕竟正在访问hash.web文件。 Confirmed with process monitor. 通过过程监控器确认。 Go figure..... For more info check this post. 去图.....有关更多信息,请查看帖子。 Issue similar to mine. 问题类似于我的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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