Poppa Mintin
Well-known member
- Joined
- Jan 4, 2018
- Messages
- 45
- Programming Experience
- 10+
Hi,
This is the first relevant Public Sub on Form1:
When I run the app. and the connection fails, 'palPC' dosn't connect, the Exception exectutes.
When I click the OK on the MessageBox I expect the code to proceed to:
'If palPC.Connected Then', and since palPC didn't connect I expect Form3 Label1 to up-date, but it doesn't.
Here is the update code, which is also in Form1:
Using a breakPoint I can see that:
Lab.Name = "Label1"
txt = "Sorry... MSI didn't accept!"
I was concerned that ' Lab.Name = "Label1" ', I expected to see "Form3.Label1".
There are three forms in this test project, and running a test on this part of the app. Form3's Label1 doesn't update, but neither does the Label1 on Form1 which may've shed a bit of light on the matter had it done.
I don't believe the fault is in the Client_Accept subroutine because when palPC does connect, everything else works correctly.
I only discovered this problem when I deliberately tried to connect to a computer that's not listening for the request. (To check that the code works).
Also, the up-date subroutine works everywhere else in the app. here for example is a line from a different subroutine, also in Form1 which does work:
UpDate(Form3.Label1, "I will be the Red player." & vbCrLf & vbCrLf & "Inviting " & palName & " to play.")
I see that in this case 'Lab.Name' is also just "Form1".
Ah! bother... but the invoke wasn't required, but I think that it shows that the rest of the subroutine works as it ought.
Single stepping through the Client_Accept subroutine code to: ' txt = "Sorry... MSI didn't accept!" ', control passes to the UpDate subroutine and at this point the invoke is required and I can watch the instructions being completed, yet when they are done and Form3 is 'Shown' again, Label1 is just as it was previously.
Poppa.
This is the first relevant Public Sub on Form1:
VB.NET:
Public Sub Client_Accept(ByVal state As Object)
Try
palPC.EndConnect(C_Token)
C_Token = Nothing
Catch ex As Exception
'MsgBox("Client_Accept :" & vbCrLf & ex.ToString)
End Try
If palPC.Connected Then
boss = True
Else
UpDate(Form3.Label1, "Sorry... " & palName & " didn't accept!")
End If
End Sub ' Client: Connected to Server... Or not.not.
When I run the app. and the connection fails, 'palPC' dosn't connect, the Exception exectutes.
When I click the OK on the MessageBox I expect the code to proceed to:
'If palPC.Connected Then', and since palPC didn't connect I expect Form3 Label1 to up-date, but it doesn't.
Here is the update code, which is also in Form1:
VB.NET:
Public Sub UpDate(ByVal Lab As Label, ByVal txt As String)
If Me.InvokeRequired Then
Me.Invoke(Sub() UpDate(Lab, txt))
Else
Lab.Text = txt
Lab.Refresh()
End If
End Sub
Lab.Name = "Label1"
txt = "Sorry... MSI didn't accept!"
I was concerned that ' Lab.Name = "Label1" ', I expected to see "Form3.Label1".
There are three forms in this test project, and running a test on this part of the app. Form3's Label1 doesn't update, but neither does the Label1 on Form1 which may've shed a bit of light on the matter had it done.
I don't believe the fault is in the Client_Accept subroutine because when palPC does connect, everything else works correctly.
I only discovered this problem when I deliberately tried to connect to a computer that's not listening for the request. (To check that the code works).
Also, the up-date subroutine works everywhere else in the app. here for example is a line from a different subroutine, also in Form1 which does work:
UpDate(Form3.Label1, "I will be the Red player." & vbCrLf & vbCrLf & "Inviting " & palName & " to play.")
I see that in this case 'Lab.Name' is also just "Form1".
Ah! bother... but the invoke wasn't required, but I think that it shows that the rest of the subroutine works as it ought.
Single stepping through the Client_Accept subroutine code to: ' txt = "Sorry... MSI didn't accept!" ', control passes to the UpDate subroutine and at this point the invoke is required and I can watch the instructions being completed, yet when they are done and Form3 is 'Shown' again, Label1 is just as it was previously.
Poppa.