OnStart()에서 RunProgram 메서드를 호출 한 윈도우 서비스를 설계했습니다.하지만 패키지를 설치할 때 서비스 콘솔에 표시되지 않습니다. 모든 제안 사항을 환영합니다. 다음과 같이 ..C#의 Windows 서비스 문제
protected override void OnStart(string[] args)
{
base.OnStart(args);
rd = new Thread(new ThreadStart(RunProgram));
rd.Start();
}
내 설치 클래스는 ....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Management;
using System.ServiceProcess;
using System.Linq;
namespace WindowsService1
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
public System.ServiceProcess.ServiceController serviceController = new ServiceController();
private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
{
serviceController.ServiceName = "MyTestingService";
ConnectionOptions coOptions = new ConnectionOptions();
coOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
mgmtScope.Connect();
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" + this.serviceController.ServiceName + "'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
this.serviceController.Start();
}
}
}
내 서비스 클래스는 다음과 같다
....입니다using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Web;
using System.Threading;
namespace WindowsService1
{
public partial class MyTestingService : ServiceBase
{
public MyTestingService()
{
InitializeComponent();
}
System.Threading.Thread rd;
protected override void OnStart(string[] args)
{
base.OnStart(args);
rd = new Thread(new ThreadStart(RunProgram));
rd.Start();
}
protected override void OnStop()
{
}
public void RunProgram()
{
//My Code to do here
}
}
}
이 좀 더 구체적으로 주시겠습니까 도움이 될 것입니다? 무슨 '서비스 콘솔'을 말하는 겁니까? 어떻게 서비스를 설치하고 있습니까? –
전체 서비스 클래스의 코드를 게시 할 수 있습니까? –
설치 관리자 클래스를 공유하십시오 (있는 경우). 서비스 콘솔 => windows에서 services.msc라고 가정합니다. 그게 맞습니까? 이러한 세부 사항을 제공하기 위해 질문을 편집하십시오. –