Sterling33
Member
- Joined
- Nov 17, 2005
- Messages
- 12
- Programming Experience
- 3-5
Hi All,
I'm hoping someone maybe able to help me out with the following problem. I have a application that I've been working on that utilizes a Class called 'User'. This class has several Functions that are called by a Click event on the main form. These functions must run and return required data that another function call will need later in the click event.
My problem is that when these funtions are called, the Window of the app freezes up until it completes. I have been reading into Backgroundworkers, and believe this maybe my answer, but am either not totally comprehending the concept of Backgroundworkers, or/and I do not see any info on how to implement it where I can run one function at a time without another kicking off. Like I said before, each function is dependant on another.
The above is a small sample of the click event with a call to 2 of the user functions (isUserExists and getAssignedUserRoles). isUserExists must run and return true before getAssignedUserRoles runs.
Below are the 2 functions from the User Class
Any help would be most appreciated.
Regards,
Ed
I'm hoping someone maybe able to help me out with the following problem. I have a application that I've been working on that utilizes a Class called 'User'. This class has several Functions that are called by a Click event on the main form. These functions must run and return required data that another function call will need later in the click event.
My problem is that when these funtions are called, the Window of the app freezes up until it completes. I have been reading into Backgroundworkers, and believe this maybe my answer, but am either not totally comprehending the concept of Backgroundworkers, or/and I do not see any info on how to implement it where I can run one function at a time without another kicking off. Like I said before, each function is dependant on another.
VB.NET:
Private Sub btnValidateUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidateUser.Click
If tbxBLUsername.Text.Length = 0 Then
'set back cursor to default
Me.Cursor() = Cursors.Default
MessageBox.Show("You must specify a BladeLogic user account name. Please enter a valid BladeLogic account, and validate again.")
Exit Sub
End If
'set cursor to application starting
Me.Cursor() = Cursors.AppStarting
blnValidationResult = BLUser.IsUserExists(BLUser.BLAdminAcct, BLUser.BLAdminPswd, BLUser.BLAdminRole, tbxBLUsername.Text)
MsgBox(blnValidationResult)
If blnValidationResult = False Then
'set back cursor to default
Me.Cursor() = Cursors.Default
MessageBox.Show("The user account specified does not exist in BladeLogic. Please verify spelling, and validate again.")
BLUser.ClearRoleNamesAndIds()
Exit Sub
Else
'set back cursor to default
Me.Cursor() = Cursors.Default
cmbxAdminRole.Enabled = True
End If
BLUser.getAssignedUserRoles(BLUser.UserName)
End Sub
The above is a small sample of the click event with a call to 2 of the user functions (isUserExists and getAssignedUserRoles). isUserExists must run and return true before getAssignedUserRoles runs.
Below are the 2 functions from the User Class
VB.NET:
Function IsUserExists(ByVal strPassedUsername As String, ByVal strPassedUserPassword As String, ByVal strPassedUserRole As String, ByVal strQueriedBLUserName As String) As Boolean
Dim prcInfo As New System.Diagnostics.ProcessStartInfo("blcli.exe", "-u " & strPassedUsername & " -s " & strPassedUserPassword & " -r " & strPassedUserRole & " RBACUser isUserExists " & strQueriedBLUserName)
prcInfo.RedirectStandardOutput = True
prcInfo.WindowStyle = ProcessWindowStyle.Hidden
prcInfo.CreateNoWindow = True
prcInfo.UseShellExecute = False
Dim prcBLCLI As System.Diagnostics.Process
prcBLCLI = System.Diagnostics.Process.Start(prcInfo)
Dim objStreamOutput As System.IO.StreamReader = prcBLCLI.StandardOutput
Dim strOutput As Boolean = objStreamOutput.ReadToEnd
prcBLCLI.WaitForExit()
If prcBLCLI.HasExited Then
If strOutput = True Then
strBLUsername = strQueriedBLUserName
Else
strBLUsername = Nothing
End If
Return strOutput
End If
prcBLCLI.Close()
End Function
VB.NET:
Sub getAssignedUserRoles(ByVal strPassedBLUserName As String)
findRoleIdsForUser(strPassedBLUserName)
ReDim arrRoleNames(arrUserRoleIds.Length - 1)
Dim intRoleIdCounter As Integer = 0
Do Until intRoleIdCounter = arrUserRoleIds.Length - 1
For Each strElement As String In arrUserRoleIds
arrRoleNames(intRoleIdCounter) = findRoleNameById(strElement)
If intRoleIdCounter = arrUserRoleIds.Length - 1 Then
Exit Do
End If
intRoleIdCounter = intRoleIdCounter + 1
Next
Loop
End Sub
Any help would be most appreciated.
Regards,
Ed