Exemplo n.º 1
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            _timer.Enabled = false;
            int str = _baseTuner.GetSignalStrength();

            Debug.WriteLine("Channel " + _current.ToString() + " Str: " + str.ToString());
            if (str != 0)
            {
                Channel actual = _baseTuner.TryChannel;
                if (actual != null)
                {
                    Debug.WriteLine("actually found channel: " + actual.ToDebugString());
                    if (_virtualChannelTuner != null)
                    {
                        List <Channel> virtualChannels = _virtualChannelTuner.GetVirtualChannels();
                        foreach (Channel ch in virtualChannels)
                        {
                            _channelList.Add(ch);
                        }
                    }
                    else
                    {
                        _channelList.Add(actual);
                    }
                    _channelList.DumpToDebug();
                }
            }

            if (Current.Equals(_max))
            {
                Stop();

                _baseTuner.KnownChannels = this.FoundChannels;

                if (_baseTuner.KnownChannels.Count > 0)
                {
                    _baseTuner.Channel = _baseTuner.KnownChannels.Items[0];
                }

                if (ChannelScanComplete != null)
                {
                    ChannelScanComplete.Invoke(this, new ChannelScanCompleteEventArgs(_channelList.Count));
                }
            }
            else
            {
                Current = new Channel(Current.PhysicalChannel + 1);
                _baseTuner.TryChannel = Current;
                curChannelCount++;
                if (ChannelScanProgressUpdate != null)
                {
                    this.ChannelScanProgress = (int)(((double)curChannelCount / (double)totalChannels) * 100.0);
                    ChannelScanProgressUpdate.Invoke(this, new EventArgs());
                }

                if (!_channelScanCancelled)
                {
                    _timer.Enabled = true;
                }
            }
        }