mirror of
https://github.com/ckaczor/SystemTemperatureStatusWindow.git
synced 2026-01-14 01:25:42 -05:00
Change to log to a file and tweak the scheduled task parameters
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.ServiceModel;
|
using System.IO;
|
||||||
|
using System.ServiceModel;
|
||||||
using Common.Debug;
|
using Common.Debug;
|
||||||
using Microsoft.Win32.TaskScheduler;
|
using Microsoft.Win32.TaskScheduler;
|
||||||
using System;
|
using System;
|
||||||
@@ -23,7 +24,13 @@ namespace SystemTemperatureService
|
|||||||
{
|
{
|
||||||
MainDispatcher = Dispatcher.CurrentDispatcher;
|
MainDispatcher = Dispatcher.CurrentDispatcher;
|
||||||
|
|
||||||
Tracer.Initialize(null, null, Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), Environment.UserInteractive);
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
|
|
||||||
|
var path = Path.GetDirectoryName(assembly.Location);
|
||||||
|
|
||||||
|
var logPath = path == null ? null : Path.Combine(path, "Logs");
|
||||||
|
|
||||||
|
Tracer.Initialize(logPath, ScheduledTaskName, Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), Environment.UserInteractive);
|
||||||
|
|
||||||
if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
|
if (args.Contains("-install", StringComparer.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
@@ -40,8 +47,8 @@ namespace SystemTemperatureService
|
|||||||
var taskDefinition = taskService.NewTask();
|
var taskDefinition = taskService.NewTask();
|
||||||
taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
|
taskDefinition.Principal.RunLevel = TaskRunLevel.Highest;
|
||||||
|
|
||||||
taskDefinition.Triggers.Add(new LogonTrigger());
|
taskDefinition.Triggers.Add(new LogonTrigger { Delay = TimeSpan.FromSeconds(30) });
|
||||||
taskDefinition.Actions.Add(new ExecAction(Assembly.GetExecutingAssembly().Location));
|
taskDefinition.Actions.Add(new ExecAction(assembly.Location));
|
||||||
taskDefinition.Settings.RestartInterval = TimeSpan.FromMinutes(1);
|
taskDefinition.Settings.RestartInterval = TimeSpan.FromMinutes(1);
|
||||||
taskDefinition.Settings.RestartCount = 3;
|
taskDefinition.Settings.RestartCount = 3;
|
||||||
taskDefinition.Settings.StartWhenAvailable = true;
|
taskDefinition.Settings.StartWhenAvailable = true;
|
||||||
@@ -81,18 +88,32 @@ namespace SystemTemperatureService
|
|||||||
{
|
{
|
||||||
Tracer.WriteLine("Starting");
|
Tracer.WriteLine("Starting");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
using (_serviceHost = new ServiceHost(typeof(SystemTemperatureService)))
|
using (_serviceHost = new ServiceHost(typeof(SystemTemperatureService)))
|
||||||
{
|
{
|
||||||
_serviceHost.Open();
|
_serviceHost.Open();
|
||||||
|
|
||||||
var application = new Application();
|
var application = new Application();
|
||||||
|
application.DispatcherUnhandledException += HandleApplicationDispatcherUnhandledException;
|
||||||
application.Run();
|
application.Run();
|
||||||
|
|
||||||
_serviceHost.Close();
|
_serviceHost.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Tracer.WriteException(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Tracer.WriteLine("Closing");
|
||||||
Tracer.Dispose();
|
Tracer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void HandleApplicationDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
|
||||||
|
{
|
||||||
|
Tracer.WriteException(e.Exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user