help with crashing application

  • Thread starter Thread starter Chris Calzaretta
  • Start date Start date
C

Chris Calzaretta

Hello
Working with system.threading.thread

Ok
I have an windows user control. It has 3 thread on it
thread 1 uploaded files types a
thread 2 upload files types b
thread 3 upload files types c

this all happens at same time Works great


Now i put a tab control on my form
i create 5 instances of my windows user control.
which allows me to have 5 different controls working at the same time

Now i start all controls to upload. after each upload the thread sleeps
depending on which tab it is on. There was a speed issue with the
application moving faster then the upload so I had to pause the thread


So My Problem is
system.invalidoperationexecption
there were not enough free threads in the threadpool


question 1:
how meny threads do you get to work with

question 2:
can you change the max number of threads in the pool


Thanks

Chris
 
By default there are 25 threads per processor.

How are you using the thread-pool threads? When you use
QueueUserWorkItem if there are not enough threads then the item just
get queued until a thread becomes available. I've queued up thousands
of items (for a test, not production app) to demonstrate to a
colleague how the thread pool worked (he was scared of it).

If you're using the thread pool to generate a thread and then keep
that thread around, then you should not be using thread pool threads
and should just be creating your own threads. Then the only limit is
based on available resources.

HTH,

Sam


Hello
Working with system.threading.thread

Ok
I have an windows user control. It has 3 thread on it
thread 1 uploaded files types a
thread 2 upload files types b
thread 3 upload files types c

this all happens at same time Works great


Now i put a tab control on my form
i create 5 instances of my windows user control.
which allows me to have 5 different controls working at the same time

Now i start all controls to upload. after each upload the thread sleeps
depending on which tab it is on. There was a speed issue with the
application moving faster then the upload so I had to pause the thread


So My Problem is
system.invalidoperationexecption
there were not enough free threads in the threadpool


question 1:
how meny threads do you get to work with

question 2:
can you change the max number of threads in the pool


Thanks

Chris

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
I am not using a thread pool. what i am doing is
windows Form
tab control
tab 1
windows control file uploader
Thread 1 upload files a
thread 2 upload files b
thread 3 upload files c
tab 2
windows control file uploader
Thread 1 upload files a
thread 2 upload files b
thread 3 upload files c

tab 3
windows control file uploader
Thread 1 upload files a
thread 2 upload files b
thread 3 upload files c



on tab 1 2 and 3 there is a addfiles button.
on click of that button i say
thd = new system.threading.thread(addressof sub)
thd2 = new system.threading.thread(addressof sub)
thd3 = new system.threading.thread(addressof sub)


so on tab1 tab 2 and tab 3 when files uploading there should be a total of 9
threads started and running. plus the 1 for the application it self. so 10
total threads

I dont need an answer here I have changed how my code works. but if you
could post your threadpool sample code that would be great.


I fixed the problem by taking off all tabs but 1 and making it a que update.
So i have a tmr watching a collection of items. if it has any it will start
3 threads and do the work.

Thanks

Chris
 
Here's the thread pool test I put together earlier. It queues up 500
items and they run and report when they start and finish. See how it
ramps up to 25 or 50 active threads (depending on number of
processors) and then at end slows back down to 0 active threads.

HTH,

Sam


Imports System.Threading

Public Class ThreadTest
Const THREAD_COUNT As Integer = 500
Private Shared _done As Integer = 0
Private Shared _active As Integer = 0
Private Shared _states(THREAD_COUNT - 1) As StateInfo

Public Shared Sub Test()
Dim workerThreads As Integer
Dim completionPortThreads As Integer
ThreadPool.GetMaxThreads(workerThreads, completionPortThreads)
Console.WriteLine("max threads: " & workerThreads & ", " &
completionPortThreads)

Console.WriteLine("Starting Test...")
For i As Integer = 0 To THREAD_COUNT - 1
Console.WriteLine("Starting thread " & i )
_states(i) = New StateInfo(i)
ThreadPool.QueueUserWorkItem(AddressOf Test2, _states(i))
Thread.Sleep(10)
Next
Console.WriteLine("Finished queueing threads...")

Do While _done < THREAD_COUNT
Thread.Sleep(250)
Loop
End Sub

Public Shared Sub Test2(ByVal state As Object)
Dim stateInf As StateInfo = DirectCast(state, StateInfo)
Dim id As Integer = stateInf.ThreadID

SyncLock _states
_active += 1
End SyncLock
Console.WriteLine("In Thread " & id & ", active " & _active & ",
beginning loop")
Thread.Sleep(3000)
Console.WriteLine("In Thread " & id & ", active " & _active & ",
finished loop")
stateInf.Done()

SyncLock _states
_active -= 1
End SyncLock
End Sub

Public Class StateInfo
Public ThreadID As Integer
Public Sub New(ByVal threadID As Integer)
Me.ThreadID = threadID
End Sub
Public Sub Done()
SyncLock _states
_done += 1
End SyncLock
End Sub
End Class

End Class




I am not using a thread pool. what i am doing is
windows Form
tab control
tab 1
windows control file uploader
Thread 1 upload files a
thread 2 upload files b
thread 3 upload files c
tab 2
windows control file uploader
Thread 1 upload files a
thread 2 upload files b
thread 3 upload files c

tab 3
windows control file uploader
Thread 1 upload files a
thread 2 upload files b
thread 3 upload files c



on tab 1 2 and 3 there is a addfiles button.
on click of that button i say
thd = new system.threading.thread(addressof sub)
thd2 = new system.threading.thread(addressof sub)
thd3 = new system.threading.thread(addressof sub)


so on tab1 tab 2 and tab 3 when files uploading there should be a total of 9
threads started and running. plus the 1 for the application it self. so 10
total threads

I dont need an answer here I have changed how my code works. but if you
could post your threadpool sample code that would be great.


I fixed the problem by taking off all tabs but 1 and making it a que update.
So i have a tmr watching a collection of items. if it has any it will start
3 threads and do the work.

Thanks

Chris

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top