運行。我知道,Windows服務無法寫入到控制檯,但不應該,因爲我繞過ServiceBase.Run
它只是運行作爲一個正常的控制檯應用程序?Windows服務參數爲控制檯應用程序
using System;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ShowCheckerService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(params string[] args)
{
#if DEBUG
Service1 myService = new Service1();
myService.OnDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
if (Environment.UserInteractive)
{
string parameter = string.Concat(args);
switch (parameter)
{
case "--install":
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
break;
case "--uninstall":
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
case "--console":
ConsoleMode();
break;
}
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
}
#endif
}
private static void ConsoleMode()
{
System.IO.File.Create(@"C:\ProgramData\ShowChecker\console.txt");
Console.WriteLine("asdf");
}
}
}
「輸出型」的價值,你有什麼想法? –
@DmitryRazumikhin沒錯!我已將它設置爲Windows應用程序。將其更改爲控制檯並立即輸出。 – Jrow