x.SetDescription("Windows Program Monitor Service Host"); x.SetDisplayName("Windows Program Monitor Service"); x.SetServiceName("Windows Program Monitor Service"); });
ProgramService
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
readonly Timer _timer; publicProgramService() { _timer = new Timer(1000) { AutoReset = true }; _timer.Elapsed += (sender, eventArgs) => Console.WriteLine($"It is {DateTime.Now} and all is well"); }
publicvoidStart() { _timer.Start(); }
publicvoidStop() { _timer.Stop(); }
Program
GETProcess
GetMainProcess()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
publicstringGetMainProcess() {
var processlist = Process.GetProcesses(); var result = "";
foreach (Process process in processlist) { if (!String.IsNullOrEmpty(process.MainWindowTitle)) { result += $"Process: {process.ProcessName}, Window title: {process.MainWindowTitle},Start Time : {process.StartTime} ,Running Time: {DateTime.Now - process.StartTime}\n"; } } return result; }