diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-03-03 18:56:58 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2020-03-03 18:56:58 +0200 |
| commit | c38f1c80f1fbdfdb758c5a0b93d045a9a5b526ad (patch) | |
| tree | 20cc57b06f4260b6f86fdaca04129e1a8ace53cd /Software/Visual_Studio/Tango.Core | |
| parent | 1b0bdf6f8148e9cc4e7e07e41e9e2d75039c1349 (diff) | |
| download | Tango-c38f1c80f1fbdfdb758c5a0b93d045a9a5b526ad.tar.gz Tango-c38f1c80f1fbdfdb758c5a0b93d045a9a5b526ad.zip | |
Machine Studio v4.1.2
PPC v1.1.5
Added BYPASS_ROCKERS to SQLExaminer config.
Started integrating FSE Remote/Console To PPC.
Added support for generic continuous request.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Tango.Core.csproj | 3 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Threading/SequencerThread.cs | 71 |
2 files changed, 73 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 7c794c276..8014ac3f2 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -98,6 +98,7 @@ <Compile Include="IO\KnownFolders.cs" /> <Compile Include="Json\ProtobufContractResolver.cs" /> <Compile Include="Threading\ActionTimer.cs" /> + <Compile Include="Threading\SequencerThread.cs" /> <Compile Include="Threading\TaskSequencer.cs" /> <Compile Include="Threading\ThreadFactory.cs" /> <Compile Include="Threading\TimeoutTask.cs" /> @@ -205,7 +206,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> diff --git a/Software/Visual_Studio/Tango.Core/Threading/SequencerThread.cs b/Software/Visual_Studio/Tango.Core/Threading/SequencerThread.cs new file mode 100644 index 000000000..603790466 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Threading/SequencerThread.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Tango.Core.Threading +{ + public class SequencerThread<T> : IDisposable + { + private Thread _queueThread; + private ProducerConsumerQueue<T> _queue; + private Action<T> _onNext; + + public int FrameRate { get; set; } + + public bool IsStarted { get; private set; } + + public SequencerThread(Action<T> onNext) + { + _onNext = onNext; + _queue = new ProducerConsumerQueue<T>(); + } + + public void Start() + { + if (!IsStarted) + { + IsStarted = true; + _queueThread = new Thread(QueueThreadMethod); + _queueThread.Name = "Sequencer Thread"; + _queueThread.IsBackground = true; + _queueThread.Start(); + } + } + + public void Push(T item) + { + _queue.BlockEnqueue(item); + } + + private void QueueThreadMethod() + { + Stopwatch watch = new Stopwatch(); + watch.Start(); + + while (IsStarted) + { + watch.Restart(); + var item = _queue.BlockDequeue(); + + if (!IsStarted) break; + + try + { + _onNext?.Invoke(item); + } + catch { } + + Thread.Sleep(Math.Max(1, (int)(FrameRate - watch.ElapsedMilliseconds))); + } + } + + public void Dispose() + { + IsStarted = false; + } + } +} |
