mirror of
https://github.com/ckaczor/ProcessCpuUsageStatusWindow.git
synced 2026-01-14 01:25:41 -05:00
Setup CPU watcher on non-UI thread
This commit is contained in:
@@ -32,9 +32,9 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
|
|
||||||
#region Initialize and terminate
|
#region Initialize and terminate
|
||||||
|
|
||||||
public void Initialize(TimeSpan updateInterval, ProcessListUpdatedDelegate callback)
|
public void Initialize(TimeSpan updateInterval, ProcessListUpdatedDelegate callback, Dispatcher dispatcher)
|
||||||
{
|
{
|
||||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
_dispatcher = dispatcher;
|
||||||
|
|
||||||
// Create a new dictionary for the process list
|
// Create a new dictionary for the process list
|
||||||
CurrentProcessList = new Dictionary<string, ProcessCpuUsage>();
|
CurrentProcessList = new Dictionary<string, ProcessCpuUsage>();
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using FloatingStatusWindowLibrary;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
using FloatingStatusWindowLibrary;
|
||||||
using ProcessCpuUsageStatusWindow.Properties;
|
using ProcessCpuUsageStatusWindow.Properties;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -18,7 +20,9 @@ namespace ProcessCpuUsageStatusWindow
|
|||||||
_floatingStatusWindow.SetText(Resources.Loading);
|
_floatingStatusWindow.SetText(Resources.Loading);
|
||||||
|
|
||||||
_processCpuUsageWatcher = new ProcessCpuUsageWatcher();
|
_processCpuUsageWatcher = new ProcessCpuUsageWatcher();
|
||||||
_processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay);
|
|
||||||
|
var dispatcher = Dispatcher.CurrentDispatcher;
|
||||||
|
Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, dispatcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user