Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 服务器未运行异常冻结我的windows服务_C#_Timer_Active Directory_Windows Services - Fatal编程技术网

C# 服务器未运行异常冻结我的windows服务

C# 服务器未运行异常冻结我的windows服务,c#,timer,active-directory,windows-services,C#,Timer,Active Directory,Windows Services,在我们的内部网中,我们有一个包含两个计时器的windows服务。第一个每5分钟工作一次,获取Active Directory用户列表并用它更新数据库;第二个每小时工作一次,并做一些其他事情 有时,网络上的维护工作开始,服务内部逻辑捕获异常并将其写入日志。它始终是同一个-服务器无法运行。之后,两个计时器似乎都停止工作,但服务的状态为“已启动”,再也没有发生任何事情 异常处理如下所示: void UserSyncTimer_Elapsed(object sender, System.Timers.E

在我们的内部网中,我们有一个包含两个计时器的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);
    }
}
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()
同步功能中有一个主要的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);
    }
}
日志如下所示:

void UserSyncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    try
    {
        new ADUsersSync().Sync();
    }
    catch(Exception exc) {
        Log.ErrorFormat("UserSyncTimer_Elapsed: Exception {0}", exc);
    }
}
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。为下一次fial提供指导,以便与公司it支持部门进行深入检查

您是否为您的
DirectoryEntry
提供了正确的LDAP地址?是的,它在其余时间都可以正常工作