Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multi-threading & Listening Sockets

Multi-threading & Listening Sockets

Scheduled Pinned Locked Moved C#
questionsysadmintestingbeta-testingjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Guinness4Strength
    wrote on last edited by
    #1

    I have written a Windows Service which creates multiple threads. Each thread listens on a seperate port, writes received messages to disk and acknowledges the receipt of each message. It works perfectly with a single thread so I started load testing multiple threads with disapointing results. I've noticed erratic behavior and am pretty sure its due to the multi-threading. This is my first true multithreaded app and wanted to get some pointers. My Windows Service basically just creates (with ThreadPool.QueueUserWorkItem) and stops the threads as necessary. The rest of the code (Listening and responding, storing port numbers and directory paths, writing messages to disk) is contained in a DLL shared by each thread. So first question is: 1. Is what I'm attempting to accomplish possible, or is it going to be a locking nightmare ? The reason I ask is that it appears I need to lock the listening loop since it is contained in a DLL used by each thread. But won't this effectively stop the rest of the the threads from listening to their ports since it is blocking? Do I need to ditch the idea of listening on multiple ports within threads and just have multiple instances of the same app on a server ? Any help would be appreciated.

    D 1 Reply Last reply
    0
    • G Guinness4Strength

      I have written a Windows Service which creates multiple threads. Each thread listens on a seperate port, writes received messages to disk and acknowledges the receipt of each message. It works perfectly with a single thread so I started load testing multiple threads with disapointing results. I've noticed erratic behavior and am pretty sure its due to the multi-threading. This is my first true multithreaded app and wanted to get some pointers. My Windows Service basically just creates (with ThreadPool.QueueUserWorkItem) and stops the threads as necessary. The rest of the code (Listening and responding, storing port numbers and directory paths, writing messages to disk) is contained in a DLL shared by each thread. So first question is: 1. Is what I'm attempting to accomplish possible, or is it going to be a locking nightmare ? The reason I ask is that it appears I need to lock the listening loop since it is contained in a DLL used by each thread. But won't this effectively stop the rest of the the threads from listening to their ports since it is blocking? Do I need to ditch the idea of listening on multiple ports within threads and just have multiple instances of the same app on a server ? Any help would be appreciated.

      D Offline
      D Offline
      David Stone
      wrote on last edited by
      #2

      You know, it might help to look at this article[^]. :) It looks kinda like what you're trying to do...but it seems like he's done all the hard work for you.

      Once you wanted revolution Now you're the institution How's it feel to be the man?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups