服务器不运行异常冻结我的Windows服务

时间:2014-09-01 09:15:40

标签: c# timer active-directory windows-services

在我们的内联网中,我们获得了一个带有2个定时器的Windows服务。第一个工作每5分钟一次,获得Active Directory用户列表并使用它更新数据库,第二个每小时工作一次,并做其他一些事情。

有时网络维护工作开始,服务内部逻辑捕获异常并将其写入日志。它始终是相同的 - 服务器不可操作。在它之后,两个计时器似乎都停止工作,但服务状态 - 已启动,并且不再发生任何事情。

异常处理如下所示:

void UserSyncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    try
    {
        new ADUsersSync().Sync();
    }
    catch(Exception exc) {
        Log.ErrorFormat("UserSyncTimer_Elapsed: Exception {0}", exc);
    }
}

在Sync函数中有主要的try catch块:

public void Sync()
{

    try
    {
        DirectoryEntry Ldap = new DirectoryEntry("LDAP://OU=Users,OU=MOS1,OU=CCE,DC=portal,DC=ru");
        DirectorySearcher searcher = new DirectorySearcher(Ldap);
        searcher.Filter = "(&(objectClass=user)(objectCategory=Person)(memberOf:1.2.840.113556.1.4.1941:=CN=All Users,OU=DL,OU=Groups,DC=portal,DC=ru)) ";
        SearchResultCollection _s = searcher.FindAll();
        foreach (SearchResult sr in _s)
        {
        //... some code ..
        }
    }
    catch (Exception e)
    {
        Log.DebugFormat("ADUsersSync Debug: in main catch and exception: {0}",           e.Message);
        Log.Error(e);
    }
}

日志如下所示:

2014-08-31 14:12:49,956 [10] DEBUG PortalService.BLL.ADUsersSync  - ADUsersSync Debug: in main catch and exception: The server is not operational.

2014-08-31 14:12:49,966 [10] ERROR PortalService.BLL.ADUsersSync  - System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational.

   at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.MoveNext()
   at PortalService.BLL.ADUsersSync.Sync()
2014-08-31 14:17:50,169 [5] DEBUG PortalService.BLL.ADUsersSync  - ADUsersSync Debug: in main catch and exception: The server is not operational.

2014-08-31 14:17:50,170 [5] ERROR PortalService.BLL.ADUsersSync  - System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational.

   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_AdsObject()
   at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
   at System.DirectoryServices.DirectorySearcher.FindAll()
   at TNTPortalService.BLL.ADUsersSync.Sync()

如何防止服务冻结?

由于没有部署SearchResultCollection而导致内存泄漏,并且它在服务器上消耗1.5GB RAM。寻找下一个小伙子与公司进行深入检查支持。

0 个答案:

没有答案