B
bhc
all-
up until just recently, i was fairly sure i'd implemented a RasDial
class in VB.NET complete with a callback to get updated status. from
this wrapper, when i throw an event back to the calling program, i can
console.writeline the state successfully. but as soon as i replace
that line with updating the UI, the program freezes, and execution
halts. no exceptions are thrown or anything (i've got the line in a
try...catch block, but nothing happens), the app just freezes. in
fact, if i just mouseover the line that causes the problem (in this
case, it's just a simple Me.Text of a form that's calling my object),
the program freezes. what's amusing is that i can successfully
observe and return Me.Left...i imagine it has something to do with the
RasDial occurring in a separate thread...but it's not working
regardless.
any help would be appreciated, thanks in advance.
relevant sample code:
---
'in a class
'The callback function for obtaining updated ras states
Private mRasCallBack As RasDialCallBack = AddressOf RasDialFunc
Public Function Dial(ByVal Parameters As RASDIALPARAMS) As IntPtr
Try
'Declare return value
Dim lReturn As Int32
'Declare handle for RAS dial attempt
Dim lHandle As IntPtr
'Reset flag that controls whether or not we're done dialing
mRasDone = False
'Start dialing
lReturn = modRASAPI.RasDial(IntPtr.Zero, Nothing,
Parameters, 0, mRasCallBack, lHandle)
'See if an error occurred
If lReturn <> 0 Then
'Get the error message
Dim lErrString As String =
modRASAPI.DecodeRASErrorNumber(lReturn)
'Throw the error
Throw New Exception(lErrString)
End If
'Return the handle
Dial = lHandle
Catch ex As Exception
Throw ex
End Try
End Function
Private Function RasDialFunc(ByVal unMsg As Integer, ByVal
rasconnstate As Integer, ByVal dwError As Integer) As Integer
Try
'Get the new state
Dim lState As RasConnState = rasconnstate
'Throw a state changed event
RaiseEvent StateChanged(lState, GetConStateSTR(lState))
'See if we're either connected or disconnected
Select Case lState
Case modRASEnums.RasConnState.Connected
'Raise a done message
ThrowDoneEvent(True, 0, "")
Case modRASEnums.RasConnState.Disconnected
'Raise a done message
ThrowDoneEvent(True, 0, "")
End Select
'See if an error occurred
If dwError <> 0 Then
'First we need to determine what the error is
Dim lErrorMessage As String
Try
'Attempt to decode the error number
lErrorMessage =
modRASAPI.DecodeRASErrorNumber(dwError)
Catch ex As Exception
'Assume the error message, if there was one
lErrorMessage = ex.Message
End Try
'Raise a done message
ThrowDoneEvent(False, dwError, lErrorMessage)
End If
Catch ex As Exception
Throw ex
End Try
End Function
---
'in the calling program
Private Sub mRAS_StateChanged(ByVal CurrentState As
pdsRAS.modRASEnums.RasConnState, ByVal CurrentStateStr As String)
Handles mRAS.StateChanged
Try
'this line works, and i can see the updated state in the
console
Console.WriteLine(CurrentState)
'this line does not work, and the app halts
Me.Text = CurrentState
Catch ex As Exception
Stop
End Try
End Sub
up until just recently, i was fairly sure i'd implemented a RasDial
class in VB.NET complete with a callback to get updated status. from
this wrapper, when i throw an event back to the calling program, i can
console.writeline the state successfully. but as soon as i replace
that line with updating the UI, the program freezes, and execution
halts. no exceptions are thrown or anything (i've got the line in a
try...catch block, but nothing happens), the app just freezes. in
fact, if i just mouseover the line that causes the problem (in this
case, it's just a simple Me.Text of a form that's calling my object),
the program freezes. what's amusing is that i can successfully
observe and return Me.Left...i imagine it has something to do with the
RasDial occurring in a separate thread...but it's not working
regardless.
any help would be appreciated, thanks in advance.
relevant sample code:
---
'in a class
'The callback function for obtaining updated ras states
Private mRasCallBack As RasDialCallBack = AddressOf RasDialFunc
Public Function Dial(ByVal Parameters As RASDIALPARAMS) As IntPtr
Try
'Declare return value
Dim lReturn As Int32
'Declare handle for RAS dial attempt
Dim lHandle As IntPtr
'Reset flag that controls whether or not we're done dialing
mRasDone = False
'Start dialing
lReturn = modRASAPI.RasDial(IntPtr.Zero, Nothing,
Parameters, 0, mRasCallBack, lHandle)
'See if an error occurred
If lReturn <> 0 Then
'Get the error message
Dim lErrString As String =
modRASAPI.DecodeRASErrorNumber(lReturn)
'Throw the error
Throw New Exception(lErrString)
End If
'Return the handle
Dial = lHandle
Catch ex As Exception
Throw ex
End Try
End Function
Private Function RasDialFunc(ByVal unMsg As Integer, ByVal
rasconnstate As Integer, ByVal dwError As Integer) As Integer
Try
'Get the new state
Dim lState As RasConnState = rasconnstate
'Throw a state changed event
RaiseEvent StateChanged(lState, GetConStateSTR(lState))
'See if we're either connected or disconnected
Select Case lState
Case modRASEnums.RasConnState.Connected
'Raise a done message
ThrowDoneEvent(True, 0, "")
Case modRASEnums.RasConnState.Disconnected
'Raise a done message
ThrowDoneEvent(True, 0, "")
End Select
'See if an error occurred
If dwError <> 0 Then
'First we need to determine what the error is
Dim lErrorMessage As String
Try
'Attempt to decode the error number
lErrorMessage =
modRASAPI.DecodeRASErrorNumber(dwError)
Catch ex As Exception
'Assume the error message, if there was one
lErrorMessage = ex.Message
End Try
'Raise a done message
ThrowDoneEvent(False, dwError, lErrorMessage)
End If
Catch ex As Exception
Throw ex
End Try
End Function
---
'in the calling program
Private Sub mRAS_StateChanged(ByVal CurrentState As
pdsRAS.modRASEnums.RasConnState, ByVal CurrentStateStr As String)
Handles mRAS.StateChanged
Try
'this line works, and i can see the updated state in the
console
Console.WriteLine(CurrentState)
'this line does not work, and the app halts
Me.Text = CurrentState
Catch ex As Exception
Stop
End Try
End Sub