如何知道是谁杀死我的线程 [英] How to know who kills my threads

查看:118
本文介绍了如何知道是谁杀死我的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的仅仅是驱逐..我想知道是谁杀死了我的线程,为什么线程。

I got a thread that is just banishing.. i'd like to know who is killing my thread and why.

我突然想起我的线程被杀害的操作系统,但我想确认这一点,如果能知道它为什么杀死它。

It occurs to me my thread is being killed by the OS, but i'd like to confirm this and if possible to know why it's killing it.

至于线程,我可以断言它至少有40分钟处决临死前,却突然死了大约5分钟。

As for the thread, i can assert it has at least 40 min of execution before dying, but it suddenly dies around 5 min.

public void RunWorker()
{
    Thread worker = new Thread(delegate()
    {
        try
        {
            DoSomethingForALongLongTime();
        }
        catch(Exception e)
        {
           //Nothing is never logged :(
           LogException(e);
           throw e;
        }
    });

    worker.IsBackground = true;
    worker.SetApartmentState(System.Threading.ApartmentState.STA);
    worker.Start();
}

编辑:解决的答案

Addressing answers

  • 的try / catch可能的例外:
    它的实施,它捕获什么:(
  • 在主线程奄奄一息:
    此线程由Web服务器,它继续运行在
  • 工作完成:
    这项工作没有完成,因为它最终影响到数据库中,我可以检查它是否是做或不该当线程死亡。
  • Try/Catch Possible exceptions:
    It's implemented and it catches nothing :(
  • Main Thread dying:
    This thread is created by the web server, which continues to run
  • Work completion:
    The work is not completed, as it finally affects the database, i can check whether it's done or not when the thread dies.

有了这些东西想到把我带到了这个问题,谁是杀害我的主题?

Having thought of these things brought me to this question, who is killing my threads??

PS。这不是夫人Goldent在房间里的蜡烛棍子生活:)

ps. It's not Lady Goldent in the living room with the candle stick :)

推荐答案

各种人(包括我自己,<一个href="http://stackoverflow.com/questions/2675910/how-to-know-who-kills-my-threads/2675951#2675951">here)指出,在IIS托管长期运行的线程是一个坏主意。你的线程将是一个IIS工作进程内运行。这些程序会定期终止(再生纸)由IIS,这将导致你的线程死亡。

Various people (including myself, here) pointed out that hosting a long-running thread in IIS is a bad idea. Your thread will being running inside an IIS 'worker process'. These processes are periodically terminated (recycled) by IIS, which will cause your thread to die.

我建议大家尽量关断IIS工作进程回收,看看是否有差别。你可以在这里找到更多的信息

I suggest that you try turning-off IIS worker process recycling to see if that makes a difference. You can find more information here.

这篇关于如何知道是谁杀死我的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆