private async Task QRCodeAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) { return; } Stopwatch QRCodeTH = new Stopwatch(); QRCodeTH.Start(); // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } DateTime LocalTimestamp = Timestamp; QRCodeMatcher matcher = new QRCodeMatcher(ColorW, ColorH); // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } // Skip if skeleton Tracking if (null != GestureManager && null != GestureManager.Skeleton) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; QRCodeWatch.Again(); // Do Job try { CopyColorData = true; String match = matcher.CheckQRCode(ColorData); if (match != null && QRCodeTH.Elapsed > WSRConfig.GetInstance().QRCodeTH) { WSRConfig.GetInstance().logInfo("QRCODE", "Match: " + match); WSRHttpManager.GetInstance().SendRequest(match); QRCodeTH.Restart(); } } catch (Exception ex) { WSRConfig.GetInstance().logError("QRCODE", ex); } QRCodeWatch.Stop(); // Wait to repeat again. await Task.Delay(interval, token); } }
private async Task QRCodeAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) return; Stopwatch QRCodeTH = new Stopwatch(); QRCodeTH.Start(); // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) await Task.Delay(dueTime, token); DateTime LocalTimestamp = Timestamp; QRCodeMatcher matcher = new QRCodeMatcher(ColorW, ColorH); // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } // Skip if skeleton Tracking if (null != GestureManager && null != GestureManager.Skeleton) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; QRCodeWatch.Again(); // Do Job try { CopyColorData = true; String match = matcher.CheckQRCode(ColorData); if (match != null && QRCodeTH.Elapsed > WSRConfig.GetInstance().QRCodeTH) { WSRConfig.GetInstance().logInfo("QRCODE", "Match: " + match); WSRHttpManager.GetInstance().SendRequest(match); QRCodeTH.Restart(); } } catch(Exception ex){ WSRConfig.GetInstance().logError("QRCODE", ex); } QRCodeWatch.Stop(); // Wait to repeat again. await Task.Delay(interval, token); } }