Queue of Threads

J

Jordi Rico

Hi
What I want to do is for using with a PDA, but I think it's a VB.NET
related question, so I ask it here.
It's simple, an user is working with the pda, and from while to while,
has to send data to a server via webservice.
As the process to the webservice can take many seconds, and the user
has to continue working, I thought to send the process in a diferent
thread, and warn the user when it has finished. The problem is that the
user can send other process to the webservice while the first is still
running. What I'm interested is in creating a queue of threads, and
don't let execute the next thread until the previous has finished.
Also I'm not interested in treating this with only SyncLock to prevent
two threads to enter the same time to the process, because I want to
execute the threads in the order I throw them, and I think that with
this only prevention, the threads can execute in the order the computer
determines...
Any idea?

Thanks
 
C

Cor Ligthert [MVP]

Jordi,

I like to use the Queue class with threads.

However you need in my opinion only one thread and let that access the queu.
You have than to synclock it, because your background worker is constantly
getting and cleaning the bottom of the queue, while your foreground worker
is filling that at the top (The representation from this text bottom top can
be visa versa what is not important).

http://msdn2.microsoft.com/en-us/library/system.collections.queue.aspx

You can use more threads of course, however mostly is the result of that a
less easy to maintanance program while the result in throughput is than
almost nothing or even possible worse.

I hope this gives an idea,

Cor
 
L

Larry Lard

Jordi said:
Hi
What I want to do is for using with a PDA, but I think it's a VB.NET
related question, so I ask it here.
It's simple, an user is working with the pda, and from while to while,
has to send data to a server via webservice.
As the process to the webservice can take many seconds, and the user
has to continue working, I thought to send the process in a diferent
thread, and warn the user when it has finished.

It would probably be easier to use the built-in asynchronous way of
calling webservices - this handles the necessary background threading
for you. There's a topic in the help titled "Accessing an XML Web
Service Asynchronously in Managed Code" which should take you through
how to do this.
 
J

Jordi Rico

Thanks Cor,
I've implemented a class with a queue and an only thread as you
said,and some flags controling everything, and it works great!
 

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

Top