0

我有一个 Windows 服务,其中有两个线程应该无限期地运行(while(true))并且都有相同的睡眠时间(这发生在 while() 下)当服务启动时,两个线程都启动并工作到某个点时间和之后第二个线程停止在日志中留下任何痕迹。异常处理在所有级别进行。

我已经设法通过为每个线程设置不同的睡眠时间来解决这个问题,我认为这不是一个最好的主意。这是我如何初始化线程..

protected override void OnStart(string[] args)
    {
Associate = new Thread(new AssociateProc().Associator) { IsBackground = true, Name = "Associator" };
Associate.Start();
DISAssociate = new Thread(new AssociateProc().DisAssociator) { IsBackground = true, Name = "DISAssociator" };
DISAssociate.Start();
     }

关联和解除关联方法 DEF IS

public void Associator()
{
  while (true)
  {
    try
    {
      //METHODS CALLED
    }
    catch(exception ex)
    {
       //Exception Handling
    }
    thread.sleep()
  }

}

请让我知道以获得更好的实施。

在试图找出场景中重复的模式时。我发现,在将信息记录到一个平面文件时,它会写入多个平面文件,当它开始写入多个文件时,第二个线程会停止而不会留下任何痕迹。 .

我使用 Microsoft.Practices.EnterpriseLibrary.Logging 进行日志记录。

4

0 回答 0