コード例 #1
0
        async void BtnPingTest_Clicked(object sender, EventArgs e)
        {
            if (mBgWorker != null && mBgWorker.IsBusy == true)
            {
                await DisplayAlert("警告", "mBgWorker.IsBusy == true", "确定");

                return;
            }

            if (mBgWorker == null)
            {
                mBgWorker = new BackgroundWorker();
                mBgWorker.WorkerReportsProgress = true;
                mBgWorker.DoWork             += Bg_DoWork;
                mBgWorker.ProgressChanged    += Bg_ProgressChanged;
                mBgWorker.RunWorkerCompleted += Bg_RunWorkerCompleted;
            }

            mContinue = true;

            App.Screen.FullScreen(); // 由于输入栏有可能导致全屏设置失效, 故这里重新设置全屏

            PingReplyModel toAdd = new PingReplyModel();

            toAdd.Foreground = "Green";
            toAdd.Content    = "开始ping";
            this.ViewModel.Result.Add(toAdd);

            this.btnPingTest.IsEnabled     = false;
            this.btnPingTestStop.IsEnabled = true;
            this.gPingDisplay.IsVisible    = true;

            mBgWorker.RunWorkerAsync(new object[] { this.txtIP.Text.Trim() });
        }
コード例 #2
0
        private void Bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.btnPingTest.IsEnabled     = true;
            this.btnPingTestStop.IsEnabled = false;
            this.gPingDisplay.IsVisible    = false;

            if (e.Error != null)
            {
                string msg = "{0}".FormatWith(e.Error.GetFullInfo());
                System.Diagnostics.Debug.WriteLine(msg);
                DisplayAlert("捕获异常", e.Error.GetFullInfo(), "确定");
            }

            if (e.Cancelled == true)
            {
                string msg = "{0}".FormatWith(e.Error.GetFullInfo());
                System.Diagnostics.Debug.WriteLine(msg);
                DisplayAlert("提示", "用户取消", "确定");
            }

            PingReplyModel toAdd = new PingReplyModel();

            toAdd.Foreground = "Red";
            toAdd.Content    = "结束ping";
            this.ViewModel.Result.Add(toAdd);
        }
コード例 #3
0
        private void Bg_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (mReply != null)
            {
                PingReplyModel toAdd = new PingReplyModel();
                try
                {
                    if (mReply.Status == System.Net.NetworkInformation.IPStatus.Success)
                    {
                        toAdd.Foreground = "Transparent";
                        toAdd.Content    = "来自 {0} 的回复: 字节={1} 时间={2}".FormatWith(mReply.Address.ToString(), mReply.Buffer.Length, mReply.RoundtripTime);
                    }
                    else
                    {
                        toAdd.Foreground = "Red";
                        toAdd.Content    = mReply.Status.ToString();
                    }
                }
                catch (Exception ex)
                {
                    toAdd.Foreground = "Red";
                    toAdd.Content    = ex.GetFullInfo();
                }

                string msg = "{0}".FormatWith(toAdd.Content);
                System.Diagnostics.Debug.WriteLine(msg);
                this.ViewModel.Result.Add(toAdd);

                this.lv.ScrollTo(toAdd, ScrollToPosition.Start, true);
            }
        }
コード例 #4
0
        private void Bg_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (mReply != null)
            {
                PingReplyModel toAdd = new PingReplyModel();
                try
                {
                    if (mReply.Status == System.Net.NetworkInformation.IPStatus.Success)
                    {
                        toAdd.Foreground = "Transparent";
                        toAdd.Content    = "来自 {0} 的回复: 字节={1} 时间={2}".FormatWith(mReply.Address.ToString(), mReply.Buffer.Length, mReply.RoundtripTime);
                    }
                    else
                    {
                        toAdd.Foreground = "Red";
                        toAdd.Content    = mReply.Status.ToString();
                    }
                }
                catch (Exception ex)
                {
                    toAdd.Foreground = "Red";
                    toAdd.Content    = ex.GetFullInfo();
                }

                string msg = "{0} - {1}".FormatWith(toAdd.Content, DateTime.Now.ToString());
                this.txtLastStatus.Text = msg;

                Grid.SetRow(this.txtLastStatus, rand.Next(colorList.Count));
                this.gPingDisplay.BackgroundColor = this.colorList[rand.Next(colorList.Count)];
            }
            else
            {
                PingReplyModel toAdd = new PingReplyModel();
                string         msg   = "Ping...";
                this.txtLastStatus.Text = msg;

                Grid.SetRow(this.txtLastStatus, rand.Next(colorList.Count));
                this.gPingDisplay.BackgroundColor = this.colorList[rand.Next(colorList.Count)];
            }
        }