저는 VS 2008 IDE에서 디버깅하려고하는데 간단한 Windows 서비스 응용 프로그램을 가지고 있지만 코드를 실행할 때마다 오류가 발생합니다. "보호 된 메모리를 읽거나 쓰려고 시도했습니다. 이것은 종종 다른 메모리가 손상되었음을 나타냅니다 . ". 이 오류는 아래 service.Stop()
줄에서 발생합니다 아래Windows 서비스 오류 : "보호 된 메모리를 읽거나 쓰려고 시도했습니다. 이것은 종종 다른 메모리가 손상되었음을 나타냅니다."
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
ServiceBase[] servicesToRun;
servicesToRun = new ServiceBase[]
{
new Service1()
};
if (Environment.UserInteractive)
{
Type type = typeof(ServiceBase);
BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
MethodInfo method = type.GetMethod("OnStart", flags);
foreach (ServiceBase service in servicesToRun)
{
method.Invoke(service, new object[] { args });
}
Console.WriteLine("Press any key to exit");
Console.Read();
foreach (ServiceBase service in servicesToRun)
{
service.Stop();//ERROR OCCURS HERE!
}
}
else
{
ServiceBase.Run(servicesToRun);
}
}
}
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
}
protected override void OnStop()
{
}
}
ServiceBase의 OnStop 메소드에는 인수가 없으므로 새 객체를 전달할 필요가 없습니다 [] {args} – pdiddy