-
Mar 15th, 2011, 03:31 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Not enough free threads in the ThreadPool
Hello There,
anybody familiar with these error? "There were not enough free threads in the ThreadPool object to complete the operation".
im calling a web service in my windows application client...
what is the possible solution to this problem?
thanks
glen
-
Mar 15th, 2011, 03:45 AM
#2
Re: Not enough free threads in the ThreadPool
Have you tried increasing the maximum number of threads available to the ThreadPool? What is the current value? What exactly are you trying to do? Is there much else going on at the same time?
-
Mar 15th, 2011, 04:05 AM
#3
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
thanks for a quick reply..
i display a GIF image loading at the same time and calling a web service(do some processing here) in other thread..
-
Mar 15th, 2011, 05:07 AM
#4
Re: Not enough free threads in the ThreadPool
So the chances are that you are either starting way tooo many threads, or they are not finishing correctly. How many threads do you think you should be using, and how long should they live for?
-
Mar 15th, 2011, 07:19 PM
#5
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
Hi Grimfort,
i only need two two thread to be running at the same time...1 is the UI thread for the GIF progressbar and 1 thread for the calling of my web service..
-
Mar 15th, 2011, 07:26 PM
#6
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
This are my code..
Code:
Private Delegate Sub DelUpdateProgressBar(ByVal Value As Boolean, ByVal errMsg As Exception, ByVal str As String)
Private _DelUpdateProgressBar As New DelUpdateProgressBar(AddressOf UpdateSendingForm)
Private Sub MultiThread()
Dim bname As String = txtSite & sDB
Dim msgRequest As String
Dim itmDetail As String
itmDetail = GetListView(ListViewItemSummary, " ")
msgRequest = "Loan " & sDB & "/" & amt & "/" & empl & "/" & _
cus_id.Replace("-", "") & "/" & TextBox1.Text.Trim & "/" & itmDetail
Try
Dim mywebserv As testwebserver.TextIN = New testwebserver.TextIN
If Not mywebserv.ValidateSenderInfo(bname) = Nothing Then
mywebserv.InsertIN(bname, msgRequest)
If Connect.State = ConnectionState.Closed Then
InitializeDB()
End If
Dim sqlcmd As SqlCommand = New SqlCommand
sqlcmd.Connection = Connect
sqlcmd.CommandText = "INSERT INTO TABLE1(col1,col2,col3,col4,col5)Values(@aa,@bb,@cc,@dd,@ee)"
sqlcmd.Parameters.Clear()
With sqlcmd.Parameters
.Add("@aa", SqlDbType.BigInt).Value = Convert.ToInt64(cus_id.Replace("-", ""))
.Add("@bb", SqlDbType.BigInt).Value = Convert.ToInt64(ptno.Replace("-", ""))
.Add("@cc", SqlDbType.Char).Value = res_id
.Add("@dd", SqlDbType.NVarChar).Value = TextBox1.Text.Trim
.Add("@ee", SqlDbType.Float).Value = Convert.ToDouble(amt)
End With
sqlcmd.ExecuteNonQuery()
HasLMTcode = True
UpdateSendingForm(False, Nothing, "")
Else
UpdateSendingForm(False, Nothing, "Error")
End If
Catch ex As Exception
UpdateSendingForm(False, ex, "")
End Try
End Sub
Private Sub ButtonProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonProcess.Click
Dim trd As New Thread(AddressOf MultiThread)
Me.Button1.Enabled = False
Me.PictureBox1.Visible = True
Me.Label1.Visible = True
trd.Start()
End Sub
Private Sub UpdateSendingForm(ByVal Value As Boolean, ByVal err As Exception, ByVal str As String)
If Me.PictureBox1.InvokeRequired Then
Me.PictureBox1.Invoke(New DelUpdateProgressBar(AddressOf UpdateSendingForm), New Object() {Value, err, str})
Else
Me.PictureBox1.Visible = Value
Me.Label1.Visible = Value
If str = "Error" Then
MessageBox.Show("Error: HO Master File might not be updated.")
Exit Sub
End If
If Not err Is Nothing Then
MessageBox.Show(err.Message)
Me.Button1.Enabled = True
Exit Sub
End If
If Value = False Then
MessageBox.Show("Request sent successfully.")
Me.Button1.Enabled = True
Me.Close()
End If
End If
End Sub
Last edited by [gja]; Mar 15th, 2011 at 09:12 PM.
-
Mar 15th, 2011, 07:46 PM
#7
Re: Not enough free threads in the ThreadPool
Are you aware that you are accessing controls on the secondary thread in that code?
-
Mar 15th, 2011, 07:53 PM
#8
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
Originally Posted by jmcilhinney
Are you aware that you are accessing controls on the secondary thread in that code?
yes im aware that's why im using delegates in accessing the control..
-
Mar 15th, 2011, 08:06 PM
#9
Re: Not enough free threads in the ThreadPool
The delegates aren't doing anything useful though. Using a delegate doesn't inherently make accessing controls thread-safe. You have to call the Invoke method of a control in order to cross the thread boundary and invoke the delegate on the UI thread, which you're not doing. You're invoking your delegates on the secondary thread so they are completely useless. Follow the CodeBank link in my signature and check out my post on Accessing Threads From Worker Threads to find out how to do it properly.
-
Mar 15th, 2011, 08:24 PM
#10
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
Originally Posted by jmcilhinney
The delegates aren't doing anything useful though. Using a delegate doesn't inherently make accessing controls thread-safe. You have to call the Invoke method of a control in order to cross the thread boundary and invoke the delegate on the UI thread, which you're not doing. You're invoking your delegates on the secondary thread so they are completely useless. Follow the CodeBank link in my signature and check out my post on Accessing Threads From Worker Threads to find out how to do it properly.
thank you very much jmc..i will check that right now and post back if i have problem..
-
Mar 15th, 2011, 09:14 PM
#11
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
i have updated my code at post #6 jmc please try to see if it is completely got it...
-
Mar 15th, 2011, 09:40 PM
#12
Re: Not enough free threads in the ThreadPool
That looks much better, although you're still accessing TextBox1 a couple of times in your 'MultiThread'. Are you still getting the same error message?
On a style note, "MultiThread" is a bad name for that method. That method has nothing to do with multi-threading. You should name the method for its purpose. The method itself doesn't care what thread it's executed on.
-
Mar 15th, 2011, 10:28 PM
#13
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
Originally Posted by jmcilhinney
That looks much better, although you're still accessing TextBox1 a couple of times in your 'MultiThread'. Are you still getting the same error message?
On a style note, "MultiThread" is a bad name for that method. That method has nothing to do with multi-threading. You should name the method for its purpose. The method itself doesn't care what thread it's executed on.
so far, for my testing i cannot reproduce the error...is that the real cause of my problem?
changed the method name also..:-)
anyway,Thank you very much for help...threading is really a very challenging topic...
-
Mar 15th, 2011, 10:32 PM
#14
Thread Starter
Addicted Member
Re: Not enough free threads in the ThreadPool
jmc, the system prevent me to rate your post...i remember i give you reputation in the past...does it mean that i cannot give you reputation again?...
i mark this thread as resolved...thank you jmc
-
Mar 15th, 2011, 10:44 PM
#15
Re: Not enough free threads in the ThreadPool
Accessing controls on the wrong thread can produce unexpected behaviour. That's why I honed in on that to begin with, i.e. I thought that that might have been the cause of your issue. If the issue has gone away then I'm guessing that it was.
You can only rate the same person in cycles of 10. Don't sweat it. Your undying admiration is quite enough reward.
-
Mar 16th, 2011, 03:05 AM
#16
Re: [RESOLVED] Not enough free threads in the ThreadPool
Bah, don't make his head any bigger!
-
Mar 16th, 2011, 07:59 AM
#17
Re: [RESOLVED] Not enough free threads in the ThreadPool
Originally Posted by Grimfort
Bah, don't make his head any bigger!
Why not? I often feel like one of the creatures in locker C18, with Agent "K" dropping by, imparting knowledge.
Grand Central Station Locker Creatures: K is back! The keeper of the light! All hail K! All hail K! Oh K can you see by the dawn's early light...
Cost of Visual Studio Ultimate: $11,899
Cost of VBFourms Membership: $0
Having jmcilhinney rate one of your posts: Priceless
Someone should pitch this to Mastercard...
Last edited by dbasnett; Mar 16th, 2011 at 08:07 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|