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. Which Better Thread or ThreadPool

Which Better Thread or ThreadPool

Scheduled Pinned Locked Moved C#
questionsysadminperformancehelpcode-review
5 Posts 3 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.
  • R Offline
    R Offline
    Rashid Mahmood
    wrote on last edited by
    #1

    Hi all, I m doing work on application like remote desktop. I have made a server and client. Server Description: server first listen for client request. Upon receiving client request server Starts a thread using ThreadStart and delegates a function that handling all the things like capturing desktop image, break that image into parts, calculating checksum for updated parts, saving image into Networkstream and sending updated region to client. I m doing all the work in one thread function. Problem: I m facing problem of CPU usage. Currently My CPU usage on server side is 45 to 60% thats not acceptable. I think that CPU usage is due to the poor threading. Someone suggest me to use threadpool but threadpool is usefull for short time threads. Can someone suggest me how can i improve CPU usage and application performance. Is there any effect by increasing the number of threads? Keeping in mind that it is real time application. Tahnx for ur suggestions

    H F 2 Replies Last reply
    0
    • R Rashid Mahmood

      Hi all, I m doing work on application like remote desktop. I have made a server and client. Server Description: server first listen for client request. Upon receiving client request server Starts a thread using ThreadStart and delegates a function that handling all the things like capturing desktop image, break that image into parts, calculating checksum for updated parts, saving image into Networkstream and sending updated region to client. I m doing all the work in one thread function. Problem: I m facing problem of CPU usage. Currently My CPU usage on server side is 45 to 60% thats not acceptable. I think that CPU usage is due to the poor threading. Someone suggest me to use threadpool but threadpool is usefull for short time threads. Can someone suggest me how can i improve CPU usage and application performance. Is there any effect by increasing the number of threads? Keeping in mind that it is real time application. Tahnx for ur suggestions

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Thread context switching is expensive and having too many threads active in your application is no better than doing everything in one thread. The ThreadPool class is for bette scalable solutions because the system will enlarge the pool if necessary (based on the performance of the application and if it can handle more) and doesn't have to create new threads but, instead, reuses existing threads which also decreases overhead. There's a lot of blogging about this at http://blogs.msdn.com[^] you should check out if you're interested. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]

      R 1 Reply Last reply
      0
      • H Heath Stewart

        Thread context switching is expensive and having too many threads active in your application is no better than doing everything in one thread. The ThreadPool class is for bette scalable solutions because the system will enlarge the pool if necessary (based on the performance of the application and if it can handle more) and doesn't have to create new threads but, instead, reuses existing threads which also decreases overhead. There's a lot of blogging about this at http://blogs.msdn.com[^] you should check out if you're interested. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Customer Product-lifecycle Experience Microsoft [My Articles] [My Blog]

        R Offline
        R Offline
        Rashid Mahmood
        wrote on last edited by
        #3

        Thanx dear, But i have generated the profile of my server application while it is sending updated desktop regions and i have noticed that least CPU time is used by the code which capture images, calculate checksum , save into memory stream and writing data on network stream. Then where is CPU used? Why it goes to upper limit of usage? I think its due to the not properly managed thread.

        1 Reply Last reply
        0
        • R Rashid Mahmood

          Hi all, I m doing work on application like remote desktop. I have made a server and client. Server Description: server first listen for client request. Upon receiving client request server Starts a thread using ThreadStart and delegates a function that handling all the things like capturing desktop image, break that image into parts, calculating checksum for updated parts, saving image into Networkstream and sending updated region to client. I m doing all the work in one thread function. Problem: I m facing problem of CPU usage. Currently My CPU usage on server side is 45 to 60% thats not acceptable. I think that CPU usage is due to the poor threading. Someone suggest me to use threadpool but threadpool is usefull for short time threads. Can someone suggest me how can i improve CPU usage and application performance. Is there any effect by increasing the number of threads? Keeping in mind that it is real time application. Tahnx for ur suggestions

          F Offline
          F Offline
          FriendlyFiend
          wrote on last edited by
          #4

          Thats not neccessarily true, you need a profiler to actually to find out whats going on, try checking some of the perf counters while your app is running, maybe you are allocating several objects and not disposing them causing the GC to run often, The network stream could also be acting asychronously If you are having more than one client connecting to your server then possibly the ThreadPool will be better as it will manage your thread allocation more efficiently.

          R 1 Reply Last reply
          0
          • F FriendlyFiend

            Thats not neccessarily true, you need a profiler to actually to find out whats going on, try checking some of the perf counters while your app is running, maybe you are allocating several objects and not disposing them causing the GC to run often, The network stream could also be acting asychronously If you are having more than one client connecting to your server then possibly the ThreadPool will be better as it will manage your thread allocation more efficiently.

            R Offline
            R Offline
            Rashid Mahmood
            wrote on last edited by
            #5

            Thanx You have mentioned that network stream could also be acting asychronously. But i m not using it asynchronously then how?

            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