473,762 Members | 8,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ThreadPool and DeadLock problems

Sam
Hi All,
I'm trying to write a simple multi-threaded windows service application
using ThreadPool and I'm running into the same problem as described by MS
article:
http://support.microsoft.com/default...5637#appliesto .
The sample code down here is from the above article. Would anyone give me
some directions how to overcome the deadlock issue with thread pull. The
exception that I get after all threads in the threadpool have been taken is
THERE WERE NOT ENOUGH FREE THREADS IN THE THREADPOOL OBJECT TO COMPLETE THE
OPERATION.
How can I reserve number of free threads in the threadpool so that the my
System.Net.Http WebRequest and the System.Net.Http WebResponse objects have
free threads to do their jobs. Thanks all in advance

Regards,
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threadin g
Imports System.Net.Sock ets

Module Module1

Sub Main()
'Set number of threads to be created for testing.
Dim testThreads As Integer = 55
Dim i As Integer

For i = 0 To testThreads
ThreadPool.Queu eUserWorkItem(N ew WaitCallback(Ad dressOf PoolFunc))
Next
Console.ReadLin e()

End Sub
Public Sub PoolFunc(ByVal state As Object)

Dim workerThreads, completionPortT hreads As Integer

ThreadPool.GetA vailableThreads (workerThreads, completionPortT hreads)

Console.WriteLi ne("WorkerThrea ds: {0}, CompletionPortT hreads: {1}",
workerThreads, completionPortT hreads)
Thread.Sleep(10 000)
Dim url As String = "http://www.msn.com"
Dim myHttpWebReques t As HttpWebRequest
Dim myHttpWebRespon se As HttpWebResponse = Nothing
' Creates an HttpWebRequest for the specified URL.
myHttpWebReques t = CType(WebReques t.Create(url), HttpWebRequest)
'Sends the HttpWebRequest, and waits for a response.
myHttpWebRespon se = CType(myHttpWeb Request.GetResp onse(),
HttpWebResponse )
myHttpWebRespon se.Close()
End Sub
End Module
Aug 4 '06 #1
1 3430
Hello Sam
Did you increase the number of MaxWorkerThread s and MaxIoThreads in
machine.config file?
We had the same problem and we changed the number.It has worked for us.
Try changing the number and if it does not work, let me know.
Deepak

"Sam" wrote:
Hi All,
I'm trying to write a simple multi-threaded windows service application
using ThreadPool and I'm running into the same problem as described by MS
article:
http://support.microsoft.com/default...5637#appliesto .
The sample code down here is from the above article. Would anyone give me
some directions how to overcome the deadlock issue with thread pull. The
exception that I get after all threads in the threadpool have been taken is
THERE WERE NOT ENOUGH FREE THREADS IN THE THREADPOOL OBJECT TO COMPLETE THE
OPERATION.
How can I reserve number of free threads in the threadpool so that the my
System.Net.Http WebRequest and the System.Net.Http WebResponse objects have
free threads to do their jobs. Thanks all in advance

Regards,
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threadin g
Imports System.Net.Sock ets

Module Module1

Sub Main()
'Set number of threads to be created for testing.
Dim testThreads As Integer = 55
Dim i As Integer

For i = 0 To testThreads
ThreadPool.Queu eUserWorkItem(N ew WaitCallback(Ad dressOf PoolFunc))
Next
Console.ReadLin e()

End Sub
Public Sub PoolFunc(ByVal state As Object)

Dim workerThreads, completionPortT hreads As Integer

ThreadPool.GetA vailableThreads (workerThreads, completionPortT hreads)

Console.WriteLi ne("WorkerThrea ds: {0}, CompletionPortT hreads: {1}",
workerThreads, completionPortT hreads)
Thread.Sleep(10 000)
Dim url As String = "http://www.msn.com"
Dim myHttpWebReques t As HttpWebRequest
Dim myHttpWebRespon se As HttpWebResponse = Nothing
' Creates an HttpWebRequest for the specified URL.
myHttpWebReques t = CType(WebReques t.Create(url), HttpWebRequest)
'Sends the HttpWebRequest, and waits for a response.
myHttpWebRespon se = CType(myHttpWeb Request.GetResp onse(),
HttpWebResponse )
myHttpWebRespon se.Close()
End Sub
End Module
Aug 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
9226
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into a table (c) re-queries another table using a subquery which references the inserted table (correlated or not)
8
2317
by: mk | last post by:
You probably suspect the answer, typically its 'yes' deadlock can occur in any multithreaded application. Even ones that employ static members. Commonly it occurs when more than one thread tries to lock a resource that another thread has already locked. A workaround is to use the Monitor object's TryEnter method, and pass a timeout value, if timeout occurs the method returns false. This pattern will save you no end of pain and...
6
2757
by: Max Adams | last post by:
Threads and ThreadPool's If I use a ThreadPool how can I tell when a thead in the threadpool has exited? I don't want to set a global member variable I would much rather be able to act on an event Also (failing this ThreadPool issue) is it possible to create an array of Worker Threads, can anyone illustrate with code please Thanks
1
3596
by: Keith O | last post by:
I know that you can queue thousands of jobs to the threadpool, but what if I want to control how many jobs are queued. Here is an algorithm I came up with. Please tell me if there is anything wrong with it, or if you have a better way to handle this: int c = 0; while (DB.readRow()) {
1
1397
by: doudou-shen | last post by:
I will use threadpool do some work with threadpool . but I haven't any information about it . who can help me! thank a lot
10
8779
by: Lenn | last post by:
Hello, I have always used a certain design pattern for multithreaded Windows app; Start new worker thread from UI thread, use events to notify UI threads when something happens, update UI controls using delegates through .BeginInvoke. I came across some code samples recently where ThreadPool class is used to start new threads. My questions; 1. what's the difference? 2. Any performance benefits?
5
2567
by: =?Utf-8?B?RkxEYXZlTQ==?= | last post by:
I'm developing an application that gets data from 100 sources (via telnet connections, but you can think stock quotes from a webservice if you like). I was planning on using the thread pool (25 at a time). I know I would start all 100 at once and as threads finish, a new thread would become available and the next one would start. However, I need to do this over and over (using an app that will run for days or longer). How can I tell...
6
1632
by: Ricardo Vazquez | last post by:
Hello everybody, I'm programming a TCP server. During the stress tests I noticed that maybe my socket-receiving thread became deaf after an hour of heavy stress. I think that the reason could be this: The processing of the received messages. Something goes wrong in this processing and the code gets stuck here. As the processing is within the receiving "while" loop, the loop gets also stuck, so that we will never reach again the...
7
7204
by: =?Utf-8?B?cmJEZXZlbG9wZXI=?= | last post by:
The following is from a simple Windows application in VS2005, which has button1 and textbox1 dragged onto a form. In StartThreads(), I call ThreadPool.QueueUserWorkItem(), then call WaitOne(). My expectation is that I would see the text generated in WasteTime() before seeing the "Hey" printout that comes after WaitOne(). Instead, I'm seeing the "Hey" as the first thing to print out in the text box. Any thoughts on why WaitOne() isn't...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3914
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.