The representation of how to use MVVM architecture the right way!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Threading;
using SignalsMVVM.Interfaces;
namespace SignalsMVVM.Models
{
public class LogController : IProcedureLogger
{
private Action<bool> IsThreadAlive { get; set; }
private Dispatcher MainDispatcher { get; set; }
private IList<BaseSignal> InputList { get; set; }
private IList<BaseSignal> OutputList { get; set; }
public LogController(Dispatcher dispatcher, IList<BaseSignal> inputList, IList<BaseSignal> outputList, Action<bool> isThreadAlive)
{
MainDispatcher = dispatcher;
InputList = inputList;
OutputList = outputList;
IsThreadAlive = isThreadAlive;
}
public void ExecuteThread()
{
IsThreadAlive(true);
foreach (BaseSignal signal in InputList)
{
MainDispatcher.Invoke(() => OutputList.Add(signal));
Thread.Sleep(signal.Delay);
}
IsThreadAlive(false);
}
}
}