vb.net 多线程 窗体 假死
代码如下代码如下:PrivateSubbtnLogin_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs...
代码如下
代码如下:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim chkl As New Login
Dim th As New Threading.Thread(AddressOf chkl.ChkLogin)
chkl.UserName = UserName.Text.Trim.ToString
chkl.Pwd = Pwd.Text.Trim.ToString
th.Start()
UserName.Enabled = False
Pwd.Enabled = False
btnLogin.Enabled = False
LoginInfo.Text = "系统正在拉取用户数据,请稍后……"
End Sub
Delegate Sub SFM()
Sub ShowfrmMain()
If Me.InvokeRequired Then
Dim dh As New SFM(AddressOf ShowfrmMain)
Me.Invoke(dh)
Else
frmMain.Show()
Me.Close()
End If
End Sub
Class Login
Public UserName As String
Public Pwd As String
Function OpenDB()
Dim Conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=DataBase/DFZJOADB.MDB")
Try
Conn.Open()
Return Conn
Catch ex As Exception
Msg(ex.ToString)
End Try
End Function
Sub ChkLogin()
Dim sql As String = "select * from UserInfo where UserName='" & UserName & "'"
Dim DRL As New OleDbCommand(sql, OpenDB)
Dim ReadLoginData As OleDbDataReader = DRL.ExecuteReader()
ReadLoginData.Read()
If ReadLoginData.HasRows Then
If Pwd = ReadLoginData(2).ToString.Trim Then
System.Threading.Thread.Sleep(3000)
frmLogin.ShowfrmMain()
Else
Msg("您输入的密码错误!")
Exit Sub
End If
Else
Msg("没有该用户数据!")
Exit Sub
End If
End Sub
End Class
但是这样窗体就会假死,拖动不了,怎么解决这个问题呢? 展开
代码如下:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim chkl As New Login
Dim th As New Threading.Thread(AddressOf chkl.ChkLogin)
chkl.UserName = UserName.Text.Trim.ToString
chkl.Pwd = Pwd.Text.Trim.ToString
th.Start()
UserName.Enabled = False
Pwd.Enabled = False
btnLogin.Enabled = False
LoginInfo.Text = "系统正在拉取用户数据,请稍后……"
End Sub
Delegate Sub SFM()
Sub ShowfrmMain()
If Me.InvokeRequired Then
Dim dh As New SFM(AddressOf ShowfrmMain)
Me.Invoke(dh)
Else
frmMain.Show()
Me.Close()
End If
End Sub
Class Login
Public UserName As String
Public Pwd As String
Function OpenDB()
Dim Conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=DataBase/DFZJOADB.MDB")
Try
Conn.Open()
Return Conn
Catch ex As Exception
Msg(ex.ToString)
End Try
End Function
Sub ChkLogin()
Dim sql As String = "select * from UserInfo where UserName='" & UserName & "'"
Dim DRL As New OleDbCommand(sql, OpenDB)
Dim ReadLoginData As OleDbDataReader = DRL.ExecuteReader()
ReadLoginData.Read()
If ReadLoginData.HasRows Then
If Pwd = ReadLoginData(2).ToString.Trim Then
System.Threading.Thread.Sleep(3000)
frmLogin.ShowfrmMain()
Else
Msg("您输入的密码错误!")
Exit Sub
End If
Else
Msg("没有该用户数据!")
Exit Sub
End If
End Sub
End Class
但是这样窗体就会假死,拖动不了,怎么解决这个问题呢? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询