我用TopShelf创建了Windows服务:
HostFactory.Run(x =>
{
x.UseAutofacContainer(BuildScope());
x.Service<BootstrapService>(s =>
{
s.ConstructUsingAutofacContainer();
s.WhenStarted(tc => tc.Start());
s.WhenStopped(tc => tc.Stop());
s.WhenSessionChanged((bs, args) => bs.SessionChanged(args));
});
x.RunAsLocalSystem();
x.SetDescription(CONST_Description);
x.SetDisplayName(CONST_DisplayName);
x.SetServiceName(CONST_ServiceName);
});
服务正在以LocalSystem身份运行。问题是,当其他用户登录windwos时,不会调用WhenSessionChanged
。为什么以及如何使此回调起作用?