【问题标题】:Storing the ID in State in .net Windows Service在 .net Windows 服务中将 ID 存储在 State 中
【发布时间】:2010-08-18 14:56:12
【问题描述】:

我有一个用 C# 开发的 .net Windows 服务。服务的 OnStart 我正在调用一个函数,该函数将 serviceName、DateTime 存储在 ServiceLog sql 表中并返回 ServiceID(表中的 ID 号)。

OnStop 我想用 StopDateTime 更新同一条记录。

上面返回的ID号不知道怎么保存。

请帮忙

【问题讨论】:

    标签: c# windows service


    【解决方案1】:

    也许我误读了你的问题,但这可能是你要找的(?):

    如果 ServiceBase 类是在启动时获取数据并在停止时更新数据的类,那么只需将您的 ServiceBase 类的 id 存储在本地变量中。 (除非你有一个帮助器/服务类来进行这种检索和更新,在这种情况下,这可能是放置它的最佳位置)

    例如

    public class MyService : ServiceBase
    {
     private int id;
    
     public override OnStart()
     {
       id = GetIdFOrProcess("someidentifier");
       .....
     }
    
     public override OnStop()
     {
      UpdateServiceStopTime(id);
      .....
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 2010-10-21
      • 2012-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多