diff --git a/src/client/spark/AW2/Misc/ThreadedBlackboard.cs b/src/client/spark/AW2/Misc/ThreadedBlackboard.cs index d00a616ae..328afb3ad 100644 --- a/src/client/spark/AW2/Misc/ThreadedBlackboard.cs +++ b/src/client/spark/AW2/Misc/ThreadedBlackboard.cs @@ -37,15 +37,6 @@ namespace mbts.spark { _bus = bus; _bb_name = name; subscribe(SparkTags.SparkTimer); - System.Threading.Thread timer_thread = new System.Threading.Thread(() => { - DateTime start_time = DateTime.Now; - while (true) { - System.Threading.Thread.Sleep(100); - _bus.post(SparkTags.SparkTimer, DateTime.Now - start_time); - } - }); - timer_thread.IsBackground = true; - timer_thread.Start(); } #region Public API diff --git a/src/client/spark/Daemons/ThreadedBlackboardDaemon.cs b/src/client/spark/Daemons/ThreadedBlackboardDaemon.cs new file mode 100644 index 000000000..1e852e785 --- /dev/null +++ b/src/client/spark/Daemons/ThreadedBlackboardDaemon.cs @@ -0,0 +1,40 @@ +#nullable enable +namespace Spark.Daemons; + +using bts.api; + +using mbts.spark; +using mbts.ui; + +using System; +using System.Composition; +using System.Threading; + +[Export(typeof(IShellDaemon))] +class ThreadedBlackboardDaemon : IShellDaemon, IDisposable { + readonly Thread thread; + bool isRunning = true; + + [ImportingConstructor] + public ThreadedBlackboardDaemon(IBus bus) { + thread = new(Start) { + IsBackground = true + }; + thread.Start(); + + void Start() { + var interval = TimeSpan.FromMilliseconds(100); + DateTime start_time = DateTime.Now; + Thread.Sleep(interval); + while (isRunning) { + bus.post(SparkTags.SparkTimer, DateTime.Now - start_time); + Thread.Sleep(interval); + } + } + } + + public void Dispose() { + isRunning = false; + thread.Join(); + } +}