Multithreaded System Service

  • Thread starter Thread starter Sonya Erb
  • Start date Start date
S

Sonya Erb

Hi to all!

I have a bit of a problem. I am new to multithreading, but it is necessary
for me to use it in a service that i am developing.
I am receiving numerous messages through a UDP port and need them to be
processed in the order that they arrived.
I would prefer it if they could be processed on a separate thread, but then
I cannot guarantee that they would be processed in the order in which I
received them.
My question is this: Is there anyway to keep only one thread alive and
continuously queue new tasks to it to ensure they are processed in order,
yet on a different thread? Or does someone have a better solution?

Thanks in advance, as I'm really stuck in a pickle.
 
Yeah, you could could create a collection that is processed by a single
thread that you just keep adding "worker objects" to. I don't advise using a
threadpool because you can't guaruntee linear operation, but if you used a
collection you could do it.

Just make sure you keep your synchronization solid. I suggest using Mutex
on something like this, because you can perform some asyncronous tasks on
the variable in question (i.e. your shared collection), while not eating up
massive amounts of CPU cycles..

-CJ
 
Hi Sonya,

When I read your message I see no reason for multithreading, in
contradiction, it needs a single thread.

Why you want to use multithreading?

If it has to do that you are expecting that you get a timing problem, than I
would look at remoting and not at multithreading.

Cor
 
CJ, thank you for your quick response.
Please forgive me, but I don't understand how that is done in VB.net. I
don't know how you can set an object to operate on a specific thread, and
still keep it alive when it is idle, while queueing new items to be
processed on it. Do you possibly have any links to some useful information
on this, or possibly some very simple sample sample code?
 
Back
Top