Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>EDIT:</p> <p>After discussion, it is apparent that you cannot access a listbox from a thread in this method, it is unsafe as per <a href="http://msdn.microsoft.com/en-us/library/ms171728%28v=vs.85%29.aspx" rel="nofollow">this article</a>. Instead, you must use the Status event from your ClientManager class. You will need to make three simple edits:</p> <p>First, update the Status Handler in Form1 to add the text to a new listbox. (Please change listbox name accordingly)</p> <pre><code>Private Sub manager_Status(message As String) Handles manager.Status ' CODE ADDED ' added code to add the text to a listbox, instead of a textbox ListBox1.Items.Add(message) End Sub </code></pre> <p>Second, Make your ClientManager RaiseStatus sub to be public. It needs to be public, so the Client Class can use it in the third step.</p> <pre><code>' CODE ADDED ' change access modifier to public Public Sub RaiseStatus(txt As String) form.Invoke(RaiseStatusInvoker, txt) End Sub </code></pre> <p>Last, update the Client Class.HandleMessage sub to use the parent's RaiseStatus Event (the one you just made public in the last step)</p> <pre><code>Private Sub HandleMessage(msg As String) Dim part() As String = msg.Split(":") Dim command As String = part(0).ToUpper() If command = "LOGIN" Then Me.name = part(1) ' This is unsafe, you cannot access the parent thread this way '**Form1.listbox1.item.add(part(1))** ' CODE ADDED ' this is safe, using the event handler. ' parent.RaiseStatus("hello world") parent.RaiseStatus(part(1)) ElseIf command = "ALL" Then parent.SendAll(Me, part(1)) ElseIf command = "PRIVATE" Then parent.SendTo(Me, part(1), part(2)) End If End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload