Esempio n. 1
0
        private void SendPollRequests(BackgroundWorker bw, DoWorkEventArgs e)
        {
            try {
                var currentPollDataIndex = -1;
                while (true)
                {
                    if (bw.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    Thread.Sleep(individualPollInterval);
                    {
                        var finishedOneRound = false;

                        do
                        {
                            ++currentPollDataIndex;

                            if (currentPollDataIndex < PollDataCollection.Count)
                            {
                                continue;
                            }
                            currentPollDataIndex = 0;
                            if (finishedOneRound)
                            {
                                goto continueOuterWhile;
                            }

                            finishedOneRound = true;
                            // ReSharper disable once AccessToModifiedClosure
                        } while (!G(() => PollDataCollection[currentPollDataIndex].IsPolling));
                    }

                    lock (sentCommandLock) {
                        PollData pollData = PollDataCollection[currentPollDataIndex];
                        ComConnection.I.Send(G(() => pollData.PollCommand));
                        sentCommand = new SentComCommandFor.PollRequest(pollData);
                    }

                    continueOuterWhile :;
                }
            } catch {
                // ignored
            }
        }
Esempio n. 2
0
 private void ComCommand_OnSend(object sender, RoutedEventArgs e)
 {
     lock (sentCommandLock) {
         if (!SilentConnect())
         {
             return;
         }
         if (!(sender is ComCommand comCommand))
         {
             return;
         }
         var command = comCommand.Dispatcher.Invoke(() => {
             comCommand.CommandStatus = "";
             return(comCommand.Command);
         });
         ComConnection.I.Send(command);
         sentCommand = new SentComCommandFor.SendCommand(comCommand);
     }
 }