473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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.HttpWebRequest and the System.Net.HttpWebResponse objects have
free threads to do their jobs. Thanks all in advance

Regards,
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threading
Imports System.Net.Sockets

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.QueueUserWorkItem(New WaitCallback(AddressOf PoolFunc))
Next
Console.ReadLine()

End Sub
Public Sub PoolFunc(ByVal state As Object)

Dim workerThreads, completionPortThreads As Integer

ThreadPool.GetAvailableThreads(workerThreads, completionPortThreads)

Console.WriteLine("WorkerThreads: {0}, CompletionPortThreads: {1}",
workerThreads, completionPortThreads)
Thread.Sleep(10000)
Dim url As String = "http://www.msn.com"
Dim myHttpWebRequest As HttpWebRequest
Dim myHttpWebResponse As HttpWebResponse = Nothing
' Creates an HttpWebRequest for the specified URL.
myHttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
'Sends the HttpWebRequest, and waits for a response.
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(),
HttpWebResponse)
myHttpWebResponse.Close()
End Sub
End Module
Aug 4 '06 #1
1 3411
Hello Sam
Did you increase the number of MaxWorkerThreads 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.HttpWebRequest and the System.Net.HttpWebResponse objects have
free threads to do their jobs. Thanks all in advance

Regards,
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threading
Imports System.Net.Sockets

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.QueueUserWorkItem(New WaitCallback(AddressOf PoolFunc))
Next
Console.ReadLine()

End Sub
Public Sub PoolFunc(ByVal state As Object)

Dim workerThreads, completionPortThreads As Integer

ThreadPool.GetAvailableThreads(workerThreads, completionPortThreads)

Console.WriteLine("WorkerThreads: {0}, CompletionPortThreads: {1}",
workerThreads, completionPortThreads)
Thread.Sleep(10000)
Dim url As String = "http://www.msn.com"
Dim myHttpWebRequest As HttpWebRequest
Dim myHttpWebResponse As HttpWebResponse = Nothing
' Creates an HttpWebRequest for the specified URL.
myHttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
'Sends the HttpWebRequest, and waits for a response.
myHttpWebResponse = CType(myHttpWebRequest.GetResponse(),
HttpWebResponse)
myHttpWebResponse.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
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...
8
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...
6
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...
1
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...
1
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
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...
5
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...
6
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...
7
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()....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.