The part which causes problem seems to be in the following part:
frmProcessing.close() 'This code does not work
If e.ProgressPercentage=0 then
msgbox("Welcom")
elseif e.ProgressPercentage=1 then
msgbox("Invalid Pswd")
End IF
This piece of code shouldn't
be the part of Progress_Changed
event. BackgroundWorker supports another delegate function RunWorkerCompleted, any change to the UI after background process completion should be done in this delegate.
So you code should look like:
Dim isValidUser as Boolean ' Global variable
Private Sub backgroundWorker1_DoWork( _
ByVal sender As Object, _
ByVal e As DoWorkEventArgs) _
Handles backgroundWorker1.DoWork
isValidUser = CheckInDataBase(Username,Pass)
End Sub
Private Sub backgroundWorker1_RunWorkerCompleted( _
ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) _
Handles backgroundWorker1.RunWorkerCompleted
frmProcessing.Close()
If isValidUser then
msgbox("Welcom")
else
msgbox("Invalid Pswd")
End IF
End Sub
NOTE: MSGBOX
is a VB6 style. Use MessageBox.Show
instead.