c# - 我想使用 WinForms C# 修改由 Windows 服务执行的对象
问题描述
我有一个运行服务的程序,如下面的代码:
public static void runService()
{
var exitCode = HostFactory.Run(x =>
{
x.Service<StayingAlive>(s =>
{
s.ConstructUsing(stayingAlive =>
{
sa = new StayingAlive();
return sa;
});
s.WhenStarted(stayingAlive => stayingAlive.Start());
s.WhenStopped(stayingAlive => stayingAlive.Stop());
});
x.RunAsLocalSystem();
x.SetServiceName("SimpleService");
x.SetDisplayName("SimpleService");
x.SetDescription("This is the simple service");
});
int exitCodeValue = (int)Convert.ChangeType(exitCode, exitCode.GetTypeCode());
Environment.ExitCode = exitCodeValue;
}
此方法在主 .cs 文件中调用。然后,我有了StayingAlive
具有许多属性和方法的类。
现在,我想同时执行一个 WinForm 以便使用 Button 修改类中的一个属性StayingAlive()
。
有没有可能?我试过使用Task
s 或Thread
s 但我卡住了。
解决方案
推荐阅读
- apache-spark - RowFactory.Create 抛出异常
- .htaccess - htaccess - 重写规则 - url 重写后重定向
- deep-learning - 如何使用两个不同大小的图像作为深度网络的输入?
- google-chrome-devtools - 我可以从 devtools 控制台截取屏幕截图吗?
- c - 将可变数量的参数传递给 Char* 数组中的条目
- logging - nsis - 要使用 detailprint 复制的文件的日志名称
- html - 创建包含图像拼贴的两列 HTML 页面
- c++ - 不一致的警告“从 'const unsigned char' 转换为 'const float' 需要缩小转换”
- android - Android 架构组件:依赖版本的 Gradle 同步错误
- mysql - 防止MySQL中JSON数组中的重复