扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Private Sub btnGetStockQuote1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnGetStockQuote1.Click Dim sq As New StockQuote sq.StockSymbol = cmbStocks1.SelectedItem sq.ChartControl = Chart1 t1 = New Thread(AddressOf sq.InvokeWebService) t1.Start() End Sub |
图5:测试该应用程序-当你选择某只股票编码并点击"获取股票报价"按钮的时候,重复调用Web服务的结果显示在图表中;但是由于该Web服务运行在后台线程上,调用它不会影响正常的UI操作。 |
图6:增强的多股票窗体-此图显示了你需要添加到默认窗体上以同时显示两只股票图形的新控件。 |
Dim t1, t2 As Thread |
Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Timer1.Tick lblThreadStatus.Text = "Thread state: " & _ t2.ThreadState.ToString End Sub |
Private Sub Chart2_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Chart2.Load '在x轴上每5点显示时间 Chart2.AxisX.Step = 5 '每个点之间用5个象素分隔 Chart2.AxisX.PixPerUnit = 5 '使图表可以滚动 Chart2.Scrollable = True '打开和关闭通讯管道- Chart2.OpenData(COD.Values, 1, COD.Unknown) Chart2.CloseData(COD.Values) End Sub |
Private Sub btnGetStockQuote2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnGetStockQuote2.Click Dim sq As New StockQuote sq.StockSymbol = cmbStocks2.SelectedItem sq.ChartControl = Chart2 t2 = New Thread(AddressOf sq.InvokeWebService) t2.Start() '激活暂停和停止按钮 btnPauseContinue.Enabled = True btnStop.Enabled = True '激活计时器控件 Timer1.Enabled = True End Sub |
图7:增强的两图表应用程序-增强的版本同时显示了两个图表。 |
Private Sub btnPauseContinue_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnPauseContinue.Click ' 如果线程处于睡眠和运行状态就挂起它 If t2.ThreadState = ThreadState.WaitSleepJoin _ Or t2.ThreadState = ThreadState.Running Then t2.Suspend() btnPauseContinue.Text = "Continue" Else ' 继续该线程 t2.Resume() btnPauseContinue.Text = "Pause" End If End Sub |
Private Sub btnStop_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnStop.Click Try If Not t2.ThreadState = ThreadState.Stopped Then btnPauseContinue.Enabled = False btnStop.Enabled = False t2.Abort() End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者