Thread problems!

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

Chris

Hi,

I did a bit of research and read some articles (mostly from the msdn)
about threading in dotnet cf. When the user is viewing records, the
most useful data is loaded onto the first screen then the app kicks
off background threads which load the rest of the information located
on other forms so records can be scrolled faster. I am using the code
below to create the threads:

Dim f1starter As ThreadStart = New ThreadStart(AddressOf func1)

Dim c As Thread = New Thread(f1starter)
c.Start()

Dim f2starter As ThreadStart = New ThreadStart(AddressOf func2)

Dim b As Thread = New Thread(f2starter)
b.Start()

My only problem with this method, or atleast that i can see, is that
if the user clicks 'next' a few times quickly so the threads havent
finished, new threads will be started while the other ones are going
so it will eventually cause a backlog of threads. Does anyone know of
any ways to stop this or even a better way of doing this?

Thanks

Chris
 
Chris said:
I did a bit of research and read some articles (mostly from the msdn)
about threading in dotnet cf. When the user is viewing records, the
most useful data is loaded onto the first screen then the app kicks
off background threads which load the rest of the information located
on other forms so records can be scrolled faster. I am using the code
below to create the threads:

Dim f1starter As ThreadStart = New ThreadStart(AddressOf func1)

Dim c As Thread = New Thread(f1starter)
c.Start()

Dim f2starter As ThreadStart = New ThreadStart(AddressOf func2)

Dim b As Thread = New Thread(f2starter)
b.Start()

My only problem with this method, or atleast that i can see, is that
if the user clicks 'next' a few times quickly so the threads havent
finished, new threads will be started while the other ones are going
so it will eventually cause a backlog of threads. Does anyone know of
any ways to stop this or even a better way of doing this?

The easiest way is probably to make each thread periodically check that
the information they're retrieving is still required.
 
Hi,

I would strongly advise you to look for another way to preload data, can
you load all the data at the beginning? If you don't have much data you
should do so.

I dont see how you can make it work the way you have it :(

Cheers,
 
Hi Chris,
How about disabling the button in the button handler after the last thread
start and have the last thread raise an event when it has loaded its data.
The event handler would be used to re-enable the button.
Bob
 
Back
Top