我有一个用C#编写的Windows服务,它充当后端数据库的一堆网络设备的代理.为了测试并添加模拟层来测试后端,我希望有一个GUI供测试操作员运行模拟.还可以将条带化版本作为演示发送出去.GUI和服务不必同时运行.实现这种决斗操作的最佳方法是什么?
编辑:这是我的解决方案,从梳理的东西这个问题,我正在运行的服务和安装.NET Windows服务不InstallUtil.exe使用这个优秀的代码 由马克Gravell
它使用以下行来测试是运行gui还是作为服务运行.
if (arg_gui || Environment.UserInteractive || Debugger.IsAttached)
Run Code Online (Sandbox Code Playgroud)
这是代码.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;
using System.ServiceProcess;
using System.Configuration.Install;
using System.Diagnostics;
namespace Form_Service
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static int Main(string[] args)
{
bool arg_install = false;
bool arg_uninstall = false;
bool arg_gui = false;
bool rethrow = false;
try
{
foreach …Run Code Online (Sandbox Code Playgroud)