2011-02-28 2 views
1

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 


     } 



    } 
} 
+0

이 좀 더 구체적으로 주시겠습니까 도움이 될 것입니다? 무슨 '서비스 콘솔'을 말하는 겁니까? 어떻게 서비스를 설치하고 있습니까? –

+0

전체 서비스 클래스의 코드를 게시 할 수 있습니까? –

+0

설치 관리자 클래스를 공유하십시오 (있는 경우). 서비스 콘솔 => windows에서 services.msc라고 가정합니다. 그게 맞습니까? 이러한 세부 사항을 제공하기 위해 질문을 편집하십시오. –

답변

0

로깅 파일이 있습니까? 어쩌면 웹 서비스에 오류가있을 수 있습니다. 웹 서비스도 디버깅 할 수 있습니다.

static void Main() 
{ 
#if (!DEBUG) 


      ServiceBase[] ServicesToRun; 
      ServicesToRun = new ServiceBase[] { new Service1Component() }; 
      ServiceBase.Run(ServicesToRun); 


#else 
      Service1Component s = new Service1Component(); 
      s.RunProgram(); 
#endif 
} 

p.s. s.RunProgram()은 디버깅에 사용할 수있는 방법입니다.

+0

서비스 코드는 정상입니다 .. 각 라인을 디버깅하여 검사했지만 문제는 배치 프로세스에 있습니다. 서비스가 서비스 콘솔에 나열되어 있지 않습니다. 제발 도와주세요 ... –

+0

@Ramiro Berrelleza 대답이 당신의 문제를 해결하지 못했습니까? 서비스 설치의 경우 열기 ** cmd ** 이 경로를 작성하십시오. ** C : \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 ** 이 명령 줄을 실행하십시오. ** InstallUtil.exe c : \ yourprojectdirectory \ bin \ Debug \ service.exe ** – maycil

0

시도해 보셨습니까? http://msdn.microsoft.com/en-us/library/zt39148a.aspx 난 당신이 또한 이 설치가 특정 키를 가지고 설치 서비스를 등록 갈까요 .NET하기 전에 기존 서비스에, "autoregister"당신은 당신의 서비스가 구축되면

+0

나는 각 단계를 꼼짝 못하게했지만 ... 내 서비스가 서비스 콘솔에 표시되지 않습니다 .... 어떻게해야합니까? –

0

처럼 매끄러운 기억, 당신은 실행해야 비주얼 스튜디오 명령 Propt에서 다음 명령을

installutil [/u[ninstall]] [options] assembly [[options] assembly] ... 

전체 정보 here

0

다음 단계를 수행했는지 여부를 확인 교차하십시오

1. Windows 서비스 프로젝트를 만든 다음 서비스 클래스의 디자인보기로 이동합니다 (service1.cs 클래스를 두 번 클릭하면됩니다).

2. 디자인보기에서 오른쪽 클릭하여 을 추가하십시오.을 추가하십시오. 그러면 ProjectInstaller.cs이라는 Installer 클래스가 만들어집니다. ProjectInstaller.cs를 사용하거나 ProjectInstaller.cs를 구성 할 때 오류가 발생하면 서비스 콘솔에 서비스가 표시되지 않을 수 있습니다.

3.Go>

a.**ServiceInstaller1** 

b.**ServiceProcessInstaller1** 

ServiceInstaller1의를 클릭하고 속성 탭

a.Edit the ServiceName with the name you want to 
    see your service in the service console. 

    b.Change the **StartType** to **Automatic**. 
로 이동 4.Right there- 두 개의 설치를 찾을 수 ProjectInstaller.cs의 디자인보기로

5. ServiceProcessInstaller1을 오른쪽 클릭하고 속성 탭으로 이동

a.Change the account to **LocalService** 

6. Save and try it. 

희망이 당신이 ........