// Background worker polls for passing until cancelled void bw_DoWork(object sender, DoWorkEventArgs e) { while (!bw.CancellationPending) { // New passings available? while (rrActiveUsb.UnreadPassings > 0) { // Get passing, create Detection object var passing = rrActiveUsb.GetNextPassing(); Trace.WriteLine(string.Format("New Passing: Transponder {0}@{1} - time: {2}", passing.TransponderCode, passing.LoopID, passing.TimeStamp), Tools.TRACE_CATEGORY_INFO); var detection = new Detection(passing, GetName(passing.TransponderCode)); // always add to transponder History this.Dispatcher.InvokeAsync(new Action(() => { TransponderHistory.Add(detection); })); // add to either danger or save zone depending on the MultiLoop configuration if (!MultiLoop) { if (!TranspondersIn.Contains(detection)) { detection.DangerZone = DangerZone.In; this.Dispatcher.InvokeAsync(new Action(() => { TranspondersOut.Remove(detection); TranspondersIn.Add(detection); })); } else { detection.DangerZone = DangerZone.Out; this.Dispatcher.InvokeAsync(new Action(() => { TranspondersIn.Remove(detection); TranspondersOut.Add(detection); })); } } else { if (passing.LoopID == 1) { detection.DangerZone = DangerZone.In; if (!TranspondersIn.Contains(detection)) { this.Dispatcher.InvokeAsync(new Action(() => { TranspondersOut.Remove(detection); TranspondersIn.Add(detection); })); } } else { detection.DangerZone = DangerZone.Out; if (!TranspondersOut.Contains(detection)) { this.Dispatcher.InvokeAsync(new Action(() => { TranspondersIn.Remove(detection); TranspondersOut.Add(detection); })); } } } } Thread.Sleep(100); } }
// Background worker polls for passing until cancelled void bw_DoWork(object sender, DoWorkEventArgs e) { while (!bw.CancellationPending) { // New passings available? while (rrActiveUsb.UnreadPassings > 0) { // Get passing, create Detection object var passing = rrActiveUsb.GetNextPassing(); Trace.WriteLine(string.Format("New Passing: Transponder {0}@{1} - time: {2}", passing.TransponderCode, passing.LoopID, passing.TimeStamp), Tools.TRACE_CATEGORY_INFO); var detection = new Detection(passing, GetName(passing.TransponderCode)); // always add to transponder History this.Dispatcher.InvokeAsync(new Action(() => { TransponderHistory.Add(detection); })); // add to either danger or save zone depending on the MultiLoop configuration if (!MultiLoop) { if (!TranspondersIn.Contains(detection)) { detection.DangerZone = DangerZone.In; this.Dispatcher.InvokeAsync(new Action(() => { TranspondersOut.Remove(detection); TranspondersIn.Add(detection); })); } else { detection.DangerZone = DangerZone.Out; this.Dispatcher.InvokeAsync(new Action(() => { TranspondersIn.Remove(detection); TranspondersOut.Add(detection); })); } } else { if (passing.LoopID == 1) { detection.DangerZone = DangerZone.In; if (!TranspondersIn.Contains(detection)) this.Dispatcher.InvokeAsync(new Action(() => { TranspondersOut.Remove(detection); TranspondersIn.Add(detection); })); } else { detection.DangerZone = DangerZone.Out; if (!TranspondersOut.Contains(detection)) this.Dispatcher.InvokeAsync(new Action(() => { TranspondersIn.Remove(detection); TranspondersOut.Add(detection); })); } } } Thread.Sleep(100); } }