VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • VB.NET处理线程

代码:

Imports SIMMGR

Imports System.Threading

Public Class Form1

Public db As New SIMMGR.simmgr_mssql

Private TH As Thread

Delegate Sub My_Delegate(res As Boolean)



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    TH = New Thread(AddressOf con2db)

    If TH.IsAlive = True Then

        TH.Join()

    Else

        TH.Start()

    End If

End Sub

''' <summary>

''' 线程

''' </summary>

''' <returns></returns>

Private Function con2db()

    Dim res = db.Connect2Db("localhost", "sim", "sa", "zhangchen", "")

    Invoke_Thread(res)

End Function



''' <summary>

''' 处理线程结果

''' </summary>

''' <param name="res"></param>

Private Sub Invoke_Thread(res As Boolean)

    Dim hander As New My_Delegate(AddressOf Deal_Delegate)

    Me.Invoke(hander, res)

End Sub



''' <summary>

''' 更新窗体

''' </summary>

''' <param name="res"></param>

Private Sub Deal_Delegate(res As Boolean)

    MsgBox(res)

End Sub

End Class


相关教程