Threading Issues

mafrosis

Well-known member
Joined
Jun 5, 2006
Messages
88
Location
UK
Programming Experience
5-10
I kind of taught myself VB.NET and sometimes I encounter a problem that feels as though its been created by my habit of doing things the "wrong" way. This might be one of those cases, so I thought Id post on the forum to see if anyone had a suggestion for dealing with this situation.

My application does lots of lengthy data processing, so I use the BackgroundWorker class to free up my user interface - and (of course) display a lovely progress bar so the user knows something is happening.

One of my colleagues who likes to "stress" test applications, promptly broke the app by clicking between several menu items rapidly, creating lots of background threads which were all doing intensive data work.

Ive written a shared data access class which uses Wait/Notify to handle a maximum amount of connections, but when he clicks buttons really fast, the code to release the connection never gets run before we run out of spare connections in the pool.. Hmm it seems like the design is flawed to me in that data class.

Essentially my question is about methods for handling this excess of threads being created by a foolish user - ThreadPools etc.. are fair enough, but really I shouldnt even let the user create multiples of a thread which actually do the same task!

Has anyone dealt with a similar issue before? Or have a method be which they handle something similar?

All/any comments welcome
Cheers
mafro
 
How many workers can go to work at the same time, ideally? Because in all my apps that use BGW cannot really go any faster by doing multiple things simulatneously I simply create a List that I post work requests into and one BGW consumes them one at a time.

If Not BGW.IsBusy Then BGW.RunWorkerAsync

or soemthing like that.. if the worker is already working, the the request is queued. Its an example of producer/consumer pattern
 
Back
Top