// Datapoint implements ...
internal interface ISynchronousWrite
{
DateTime LastWrite { get; set; }
object BufferedValue { get; set; }
WriteResult LastWriteResult { get; set; }
void WriteBufferedValueToDevice();
}
// Item broker creates...
private CancellationTokenSource cancellationTokenSource;
private CancellationToken ct;
private bool exitWriteTask = false;
cancellationTokenSource = new CancellationTokenSource();
ct = cancellationTokenSource.Token;
var intervalWritingTask = Task.Run(() =>
{
while (!exitWriteTask)
{
if (Connection.IsConnected)
{
foreach (var key in inputDatapointBuffer.Keys)
{
var dp = key as ISynchronousWrite;
var lastTempWriteTime = dp.LastWrite;
if (inputDatapointBuffer[key] < lastTempWriteTime)
{
dp.WriteBufferedValueToDevice();
inputDatapointBuffer[key] = lastTempWriteTime;
}
}
}
Thread.Sleep(10);
}
}, ct);
// Implementation
private WriteResult BufferValue(object value)
{
BufferedValue = value;
LastWrite = DateTime.Now;
return LastWriteResult;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter