Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:01:34+00:00 2026-06-13T20:01:34+00:00

I’m not even sure I understand this situation enough to come up with a

  • 0

I’m not even sure I understand this situation enough to come up with a proper title. I come from a modest understanding of VB6 and having to climb a steep learning curve for VB 2010.

I am trying to create a multi-client server program that will communicate with my Enterprise iPhone app. I found a relatively simple example to build upon here: http://www.strokenine.com/blog/?p=218. I have been able to modify the code enough to make it work with my app, but with one glitch: I can’t get access to the controls on the form to add items, even though the method is invoked within the form’s class. (I tried this on the original code too, and it does the same thing. I don’t know how the author managed to get it to work.)

Here’s the code segment in question:

Public Class Server 'The form with the controls is on/in this class.
Dim clients As New Hashtable 'new database (hashtable) to hold the clients


    Sub recieved(ByVal msg As String, ByVal client As ConnectedClient)
    Dim message() As String = msg.Split("|") 'make an array with elements of the message recieved
    Select Case message(0) 'process by the first element in the array
        Case "CHAT" 'if it's CHAT
            TextBox3.Text &= client.name & " says: " & " " & message(1) & vbNewLine 'add the message to the chatbox
            sendallbutone(message(1), client.name) 'this will update all clients with the new message
            '                                       and it will not send the message to the client it recieved it from :)
        Case "LOGIN" 'A client has connected
            clients.Add(client, client.name) 'add the client to our database (a hashtable)
            ListBox1.Items.Add(client.name) 'add the client to the listbox to display the new user
    End Select

End Sub

Under Case “LOGIN” the code tries to add the login ID to the listbox. It throws an exception: “A first chance exception of type ‘System.InvalidOperationException’ occurred in System.Windows.Forms.dll” The listbox (all controls, for that matter) is in the same class, Server.vb and Server.vb [Design].

The data comes in from another class that is created whenever a client logs on, which raises the event that switches back to the Server class:

Public Class ConnectedClient

Public Event gotmessage(ByVal message As String, ByVal client As ConnectedClient)    'this is raised when we get a message from the client
Public Event disconnected(ByVal client As ConnectedClient)    'this is raised when we get the client disconnects

Sub read(ByVal ar As IAsyncResult) 'this will process all messages being recieved
    Try
        Dim sr As New StreamReader(cli.GetStream) 'initialize a new streamreader which will read from the client's stream
        Dim msg As String = sr.ReadLine() 'create a new variable which will be used to hold the message being read
        RaiseEvent gotmessage(msg, Me) 'tell the server a message has been recieved. Me is passed as an argument which represents 
        '                               the current client which it has recieved the message from to perform any client specific
        '                               tasks if needed
        cli.GetStream.BeginRead(New Byte() {0}, 0, 0, AddressOf read, Nothing) 'continue reading from the stream
    Catch ex As Exception
        Try 'if an error occurs in the reading purpose, we will try to read again to see if we still can read
            Dim sr As New StreamReader(cli.GetStream) 'initialize a new streamreader which will read from the client's stream
            Dim msg As String = sr.ReadLine() 'create a new variable which will be used to hold the message being read
            RaiseEvent gotmessage(msg, Me) 'tell the server a message has been recieved. Me is passed as an argument which represents 
            '                               the current client which it has recieved the message from to perform any client specific
            '                               tasks if needed
            cli.GetStream.BeginRead(New Byte() {0}, 0, 0, AddressOf read, Nothing) 'continue reading from the stream
        Catch ' IF WE STILL CANNOT READ
            RaiseEvent disconnected(Me)  'WE CAN ASSUME THE CLIENT HAS DISCONNECTED
        End Try

    End Try
End Sub

I hope I am making sense with all this. It all seems to bounce back and forth, it seems so convoluted.

I’ve tried using Me.listbox1 and Server.listbox1 and several other similar structures, but to no avail.

I’m reading a lot about Invoke and Delegates, but would that be necessary if the method and the control are in the same class? Or do I have a fundamental misperception of what a class is?

Many thanks for any help I can get.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:01:36+00:00Added an answer on June 13, 2026 at 8:01 pm
        Private Delegate Sub UpdateListDelegate(byval itemName as string)
        Private Sub UpdateList(byval itemName as string)
        If Me.InvokeRequired Then
            Me.Invoke(New UpdateListDelegate(AddressOf UpdateList), itemName)
        Else
            ' UpdateList
            ' add list add code
            ListBox1.Items.Add(itemName)
        End If
        End Sub
    

    Add above, then replace:

       ListBox1.Items.Add(client.name)
    

    to

       UpdateList(client.name)
    

    Does it work? check the syntax, may have typo as I type it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.