0
IDE가 나타납니다 VS 2010, Windows 서비스가 나는 간단한 Windows 서비스를 만들어코드를
4.0 .NET,이 코드를 사용하여이 서비스를 테스트 : 여기
protected override void OnStart(string[] args)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"F:\22Yardz_Pro\" + "error.txt", true))
{
file.WriteLine("Service is working \n");
}
//ReceiveMsmqMessage();
}
을 설치 프로그램에 내가
** protected override void OnStart(string[] args)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"F:\MyProj\" + "error.txt", true))
{
file.WriteLine("Service is working \n");
}
ReceiveMsmqMessage();
}
private static void ReceiveMsmqMessage()
{
//string MsmqPath = System.Configuration.ConfigurationManager.AppSettings["MsmqPath"];
MessageQueue queue = new MessageQueue(@".\Private$\MyProjQ");
System.Messaging.Message myMessage = queue.Receive();
myMessage.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });
string message = (myMessage.Body.ToString());
string labelName = myMessage.Label;
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"F:\MyProj\" + "error.txt", true))
{
file.WriteLine("Service started " + message + " \n");
}
}**
에 내 코드를 변경 한 다음
serviceProcessInstaller1. Account = Local System
을 설정 한
내 msmq 코드가 작동하지 않는 이유를 말해 줄 수 있습니까? winForms 프로젝트에서이 코드가 잘 작동하는지 테스트했습니다. 디버깅 모드에서도 작동하지만 cmd를 사용하여 서비스를 설치하고 services.msc를 사용하면 나는이 서비스를 시작한다. 오류가 발생한다.
The _MsmqTesting service on local computer has started and then stopped. Some services stop automatically if there are not in use by other services or programs
내가 뭘하고 있는지 나에게 제안 해 줄 수 있니?
Windows 서비스 프로그램은 약간 특별합니다. 일반적으로 작업을 수행하기 위해 스레드를 시작한 다음 서비스 관리자에게 즉시 반환하는 것을 제외하고는 OnStart() 메서드에서 아무 것도하지 말아야합니다. Windows 서비스 프로그램을 만드는 방법에 대한 자습서를 살펴보십시오. – RenniePet
테스트에 유용한 트릭은 Windows 서비스 프로그램과 콘솔 프로그램으로 실행될 수 있도록 프로그램을 만드는 것입니다. 이 작업을 수행하는 방법에 대한 몇 가지 자습서가 있습니다. Google의 "Windows 응용 프로그램을 콘솔 응용 프로그램으로 사용"을 시도해보십시오. – RenniePet