Windows服务锁定了组件上的负载 [英] Windows service locks up on assembly load

查看:140
本文介绍了Windows服务锁定了组件上的负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows服务在C#编写。它包括一个独立的控制台模式,以及为调试目的。它的工作原理,它已经运行在精细几乎每一台计算机上,但我们没有进入的情况下此服务锁定,当您尝试启动它,因为超时而那就会被杀死。但在同一台机器上的控制台模式下运行时,它启动的罚款。

这是一个痛苦的调试,因为我实际上没有进入机器发生这种情况,我必须去通过人代理。但一堆试验和错误调试后,我终于缩小的原因到装配载荷。当它击中了第一次提到在一个特定的DLL中的任何数据类型,它就停在那里,根据日志文件中。它甚至不给一个例外,它只是锁定了。

经过进一步检查,似乎这不是锁定永久,它只是需要约40秒,以实际完成加载的库,它是足够长的Windows服务,以决定终止该进程。

任何线索如何调试这种情况?

下面是关于,我可以重现它最简单的解决方案。 之​​前显示出来,但十一五期间和后不知道。

 私有静态无效LoadAssembly()
{
    日志(十一五期间);
    MyNameSpace.MyClass X =新MyNameSpace.MyClass();
}

静态无效的主要(字串[] args)
{
    尝试
    {
        //离开了code来处理命令行参数
        // ...
        //

        日志(之前);
        LoadAssembly();
        日志(后);
        如果(Environment.UserInteractive)
        {
            日志(开始在控制台模式);
            ConnectionManager.Listen();
        }
        其他
        {
            日志(启动服务模式);
            ServiceBase.Run(新RunAsService());
        }

    }
    赶上(例外前)
    {
        日志(ex.ToString());
    }
}
 

解决方案

正在采取45秒连接的组件,它会尝试连接到互联网加载之前验证一些有关的组件,但特定机器上它的封锁通过防火墙。经过尝试启动30秒后,Windows服务经理放弃并终止进程。

移动组件的装载后才服务已开始允许其正常启动(虽然有45秒的延迟才开始响应)。

这看起来好像是与生成发行者证据。从这里 http://msdn.microsoft.com/en-us/library/bb629393的.aspx

  

我们建议服务使用的元素,以提高启动性能。使用这种元件还可以帮助避免延误,可能会导致超时和服务启动的取消。

把在App.config文件中的以下摆脱了延迟的:

 <结构>
    <运行>
        < generatePublisherEvidence启用=FALSE/>
    < /运行>
< /结构>
 

I have a Windows Service written in C#. It includes a standalone console mode as well, for debugging purposes. It works fine on almost every computer it's been run on, but we ran into a situation where this service locks up when you try to start it, and then it gets killed because of timeout. But when running it in console mode on the same machine, it starts up fine.

It's a pain to debug because I don't actually have access to the machine this is happening on, I have to go through a human proxy. But after a bunch of trial and error debugging, I finally narrowed the cause down to assembly load. When it hits the first reference to any data type in a specific dll, it stops right there, according to the log file. It's not even giving an exception, it just locks up.

[Edit] After further examination, it appears it's not locking up permanently, it just takes about 40 seconds to actually finish loading the library, which is long enough for Windows services to decide to kill the process.

Any clue how to debug this kind of situation?

Here's about the simplest solution that I can reproduce it with. "Before" shows up, but "During" and "After" do not.

private static void LoadAssembly()
{
    Log("During");
    MyNameSpace.MyClass x = new MyNameSpace.MyClass();        
}

static void Main(string[] args)
{
    try
    {
        // Leaving out code to handle command line parameters
        // ...
        //

        Log("Before");
        LoadAssembly();
        Log("After");
        if (Environment.UserInteractive)
        {
            Log("Starting in console mode");
            ConnectionManager.Listen();
        }
        else
        {
            Log("Starting in service mode");
            ServiceBase.Run(new RunAsService());
        }

    }
    catch (Exception ex)
    {
        Log(ex.ToString());
    }
}

解决方案

The assembly was taking 45 seconds to connect, it tries to connect to the internet to verify something about the assembly before loading it, but on that particular machine it's blocked by the firewall. After 30 seconds of trying to start, Windows service manager gives up and kills the process.

Moving the loading of the assembly until after the service has been started allowed it to start up properly (although with a 45 second delay before it starts responding).

It looks like it was related to generating publisher evidence. From here http://msdn.microsoft.com/en-us/library/bb629393.aspx:

We recommend that services use the element to improve startup performance. Using this element can also help avoid delays that can cause a time-out and the cancellation of the service startup.

Putting the following in the app.config file got rid of the delay:

<configuration>
    <runtime>
        <generatePublisherEvidence enabled="false"/>
    </runtime>
</configuration>

这篇关于Windows服务锁定了组件上的负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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