Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate?
Pause threads or recreate? Pause threads or recreate?
Pause threads or recreate?
Go Back  Xtreme Visual Basic Talk > > > Pause threads or recreate?


Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2009, 08:00 AM
shaul_ahuvaPause threads or recreate? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default Pause threads or recreate?


I've created a class that manages two threads for reading from the stdout and stderr streams of a child process. The class is working fine now by pausing the threads when they aren't needed by calling Thread.Sleep(Timeout.Infinite), but I have a question about resource usage...

Does it make more sense to allow the threads to finish execution and recreate them when needed or to just sleep them and then wake the threads up via Thread.Interrupt when needed?
Reply With Quote
  #2  
Old 02-20-2009, 08:46 AM
AtmaWeapon's Avatar
AtmaWeaponPause threads or recreate? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

If the threads are going to spend most of their lives idle, it's probably best to use thread pool threads. Every thread you create takes time and comes with 1024 bytes of overhead, and the thread pool's got plenty of them already created. If you happen to need more than the thread pool has, it manages queuing you requests for you. Take a look at the ThreadPool class and see what you think.

If it were me, I'd use QueueUserWorkItem() to look for output; when the worker method finishes the thread isn't destroyed but returned to the thread pool.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate? Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate? Pause threads or recreate?
Pause threads or recreate?
Pause threads or recreate?
 
Pause threads or recreate?
Pause threads or recreate?
 
-->