Trouble threading windows service TCP socket client RRS feed

  • Question

  • I'm trying to build a multithreaded SMPP client with VS2008 and I'm getting bogged down in threading. Basically my main parent thread will interact with the windows service scheduler, get registry settings, and get a list of SMPP servers to connect to. Then it will launch a thread for each SMPP connection, which will need to keep it's TCP socket open to receive messages with, so the thread must remain running even if there aren't any events happening (no messages to receive)... but I can't seem to get it figured out.

    Here's the basic thread hierarchy I'm shooting for;

    - parent thread (windows service)

        - SMPP connection threads (could be up to 100 threads/connections)


    I'm pulling SMPP channel data from a database into a recordset and launching the child SMPP threads using the following code;

        While oRS.Read()

            oChannel = New classSMPPChannel 'create new SMPP object

            oChannel.ChannelID = oRS("ChannelID").ToString

            Threading.ThreadPool.QueueUserWorkItem(AddressOf oChannel.Start, oChannel)

            oChannel = Nothing 'kill object

        End While

    The Start sub in the oChannel object does run, but once that sub is finished running the thread ends. In the Start sub, it calls other code that initiates a connection to the remote SMPP server, but that code asynchronously waits for an event to be raised regarding the connection status. Once the sub finishes, the async connection being attempted doesn't seem to be able to pin the thread down.


    The bottom line here is that I want each child thread to kind of operate like it's own independent client process. Is that even possible? Do I need to move all my SMPP connection management logic into my main/parent thread and make this a single-threaded application? I really hope not. 


    Thanks in advance!


    • Edited by ishmell Sunday, January 22, 2012 8:34 AM
    Sunday, January 22, 2012 8:31 AM


All replies