如何基于Service Fabric中的取消令牌停止Topshelf服务?

问题描述 投票:0回答:1

我有一个使用Topshelf在Service Fabric下运行的有状态服务。问题是在升级时,我收到错误消息,因为当RunAsync方法触发CancellationToken时,服务没有停止(RunAsync对属性“ RunAsyncSlowCancellation”报告了警告)。如何使用令牌停止服务?

public static TopshelfExitCode RunServiceHost(CancellationToken token)
{
  return HostFactory.Run(x =>
  { 
      x.Service<MyService>(s =>
      {
          s.ConstructUsing(name => new MyService());
          s.WhenStarted((tc,a) => tc.Start(a));
          s.WhenStopped((tc, a) =>tc.Start(a));
      });
  });
}
.net .net-core azure-service-fabric topshelf
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.