相关疑难解决方法(0)

如何编写c#服务,我也可以作为winforms程序运行?

我有一个用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)

c# service installer windows-services winforms

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

installer ×1

service ×1

windows-services ×1

winforms ×1