我有一个使用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.Stop(a));
});
});
}
答案 0 :(得分:0)
我认为,当令牌被取消时,您应该能够使用HostControl
a
通过回调(CancellationToken.Register
使用s.EnableShutdown();
Requirement already satisfied: setuptools>=34.0.0 in ./venv/lib/python3.7/site-packages (from google-api-core<2dev,>=1.18.0->google-api-python-client) (41.2.0)
来停止服务。
确保启用关机:
/Library/