mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 09:43:46 +00:00
Changed the update-loop to be a single thread instead of a timer
This commit is contained in:
parent
bc2508e4ac
commit
4e8be36174
@ -3,13 +3,10 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
|
||||||
using System.Windows.Media;
|
|
||||||
using Artemis.DeviceProviders;
|
using Artemis.DeviceProviders;
|
||||||
using Artemis.ViewModels;
|
using Artemis.ViewModels;
|
||||||
using Ninject.Extensions.Logging;
|
using Ninject.Extensions.Logging;
|
||||||
using Color = System.Drawing.Color;
|
using Color = System.Drawing.Color;
|
||||||
using Timer = System.Timers.Timer;
|
|
||||||
|
|
||||||
namespace Artemis.Managers
|
namespace Artemis.Managers
|
||||||
{
|
{
|
||||||
@ -21,7 +18,8 @@ namespace Artemis.Managers
|
|||||||
private readonly DebugViewModel _debugViewModel;
|
private readonly DebugViewModel _debugViewModel;
|
||||||
private readonly DeviceManager _deviceManager;
|
private readonly DeviceManager _deviceManager;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly Timer _loopTimer;
|
//private readonly Timer _loopTimer;
|
||||||
|
private readonly Task _loopTask;
|
||||||
private readonly ModuleManager _moduleManager;
|
private readonly ModuleManager _moduleManager;
|
||||||
|
|
||||||
public LoopManager(ILogger logger, ModuleManager moduleManager, DeviceManager deviceManager,
|
public LoopManager(ILogger logger, ModuleManager moduleManager, DeviceManager deviceManager,
|
||||||
@ -33,10 +31,10 @@ namespace Artemis.Managers
|
|||||||
_debugViewModel = debugViewModel;
|
_debugViewModel = debugViewModel;
|
||||||
|
|
||||||
// Setup timers
|
// Setup timers
|
||||||
_loopTimer = new Timer(40);
|
//_loopTimer = new Timer(40);
|
||||||
_loopTimer.Elapsed += LoopTimerOnElapsed;
|
//_loopTimer.Elapsed += LoopTimerOnElapsed;
|
||||||
_loopTimer.Start();
|
//_loopTimer.Start();
|
||||||
|
_loopTask = Task.Factory.StartNew(ProcessLoop);
|
||||||
_logger.Info("Intialized LoopManager");
|
_logger.Info("Intialized LoopManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,22 +47,45 @@ namespace Artemis.Managers
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_loopTimer.Stop();
|
_loopTask.Dispose();
|
||||||
_loopTimer.Dispose();
|
//_loopTimer.Stop();
|
||||||
|
//_loopTimer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoopTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
|
private void ProcessLoop()
|
||||||
{
|
{
|
||||||
try
|
//TODO DarthAffe 14.01.2017: A stop-condition and a real cleanup instead of just aborting might be better
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
Render();
|
try
|
||||||
}
|
{
|
||||||
catch (Exception e)
|
long preUpdateTicks = DateTime.Now.Ticks;
|
||||||
{
|
|
||||||
_logger.Warn(e, "Exception in render loop");
|
Render();
|
||||||
|
|
||||||
|
int sleep = (int)(40f - ((DateTime.Now.Ticks - preUpdateTicks) / 10000f));
|
||||||
|
if (sleep > 0)
|
||||||
|
Thread.Sleep(sleep);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Warn(e, "Exception in render loop");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//private void LoopTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
|
||||||
|
//{
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// Render();
|
||||||
|
// }
|
||||||
|
// catch (Exception e)
|
||||||
|
// {
|
||||||
|
// _logger.Warn(e, "Exception in render loop");
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
public Task StartAsync()
|
public Task StartAsync()
|
||||||
{
|
{
|
||||||
return Task.Run(() => Start());
|
return Task.Run(() => Start());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user