C# 用于测试新创建的Windows服务的工具?
有没有工具或方法来测试我的Windows服务? 它在VisualStudio2010中运行良好 我使用Advanced Installed创建安装包(MSI),但它无法启动C# 用于测试新创建的Windows服务的工具?,c#,visual-studio-2010,testing,windows-services,C#,Visual Studio 2010,Testing,Windows Services,有没有工具或方法来测试我的Windows服务? 它在VisualStudio2010中运行良好 我使用Advanced Installed创建安装包(MSI),但它无法启动 干杯您的应用程序中有任何日志记录吗?这可能是第一个检查修复方法的地方。要有一个“工具”来测试“某些windows服务”是相当困难的。如果您从日志记录中了解到更多详细信息,但无法找出问题所在,请告知它,以便我们能够提供帮助。您的应用程序中是否有日志记录?这可能是第一个检查修复方法的地方。要有一个“工具”来测试“某些window
干杯您的应用程序中有任何日志记录吗?这可能是第一个检查修复方法的地方。要有一个“工具”来测试“某些windows服务”是相当困难的。如果您从日志记录中了解到更多详细信息,但无法找出问题所在,请告知它,以便我们能够提供帮助。您的应用程序中是否有日志记录?这可能是第一个检查修复方法的地方。要有一个“工具”来测试“某些windows服务”是相当困难的。如果您从日志记录中了解到更多详细信息,但无法找出问题所在,请告诉它,以便我们能够提供帮助。您无法直接运行Windows服务:您必须安装并启动该服务 由于在开发服务时安装服务往往不方便,因此有必要修改服务的引导代码,以检测它是作为服务运行还是以交互方式运行,在后一种情况下,显示Windows窗体
ServiceBase service = ...;
if (Environment.UserInteractive)
{
// run as application
Application.EnableVisualStyles();
Application.Run(new SomeForm()); // the form should call OnStart on the service
}
else
{
// run as service
ServiceBase.Run(service);
}
无法直接运行Windows服务:必须安装并启动该服务 由于在开发服务时安装服务往往不方便,因此有必要修改服务的引导代码,以检测它是作为服务运行还是以交互方式运行,在后一种情况下,显示Windows窗体
ServiceBase service = ...;
if (Environment.UserInteractive)
{
// run as application
Application.EnableVisualStyles();
Application.Run(new SomeForm()); // the form should call OnStart on the service
}
else
{
// run as service
ServiceBase.Run(service);
}
查看以简化调试和服务安装(我已经成功地完成了这项工作)。还建议调整log4net并以交互模式将其记录到控制台
class TheService : ServiceBase
{
static void Main(string[] args)
{
if (!Environment.UserInteractive)
{
Run(new TheService());
}
else
{
// If interactive, start up as a console app for easy debugging and/or installing/uninstalling the service
switch (string.Concat(args))
{
case "/i":
ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
break;
case "/u":
ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
default:
Console.WriteLine("Running service in console debug mode (use /i or /u to install or uninstall the service)");
var service = new TheService();
service.OnStart(null);
Thread.Sleep(Timeout.Infinite);
break;
}
}
}
}
查看以简化调试和服务安装(我已经成功地完成了这项工作)。还建议调整log4net并以交互模式将其记录到控制台
class TheService : ServiceBase
{
static void Main(string[] args)
{
if (!Environment.UserInteractive)
{
Run(new TheService());
}
else
{
// If interactive, start up as a console app for easy debugging and/or installing/uninstalling the service
switch (string.Concat(args))
{
case "/i":
ManagedInstallerClass.InstallHelper(new[] { Assembly.GetExecutingAssembly().Location });
break;
case "/u":
ManagedInstallerClass.InstallHelper(new[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
default:
Console.WriteLine("Running service in console debug mode (use /i or /u to install or uninstall the service)");
var service = new TheService();
service.OnStart(null);
Thread.Sleep(Timeout.Infinite);
break;
}
}
}
}
我假设您正在使用installer类创建和安装服务(从System.Configuration.install.installer派生)?如果是这样,请将此行代码放入安装程序的ctr或ONBEFORESTALL override。然后可以附加调试器,并调试安装过程:
System.Diagnostics.Debugger.Break()
我假设您正在使用installer类创建和安装服务(从System.Configuration.install.installer派生)?如果是这样,请将此行代码放入安装程序的ctr或ONBEFORESTALL override。然后可以附加调试器,并调试安装过程:
System.Diagnostics.Debugger.Break()
你有错误吗?如果是,什么类型?@Rhapsody I使用Advanced installed安装服务,但无法启动!你能在Windows事件日志中找到任何错误吗?你得到任何错误吗?如果是,什么类型?@Rhapsody I使用Advanced installed安装服务,但无法启动!您能在Windows事件日志中找到任何错误吗?