S
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.aspx?scid=kb;en-us;815637#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
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.aspx?scid=kb;en-us;815637#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