|
-
Sep 20th, 2007, 03:38 PM
#1
[VB2005] Asynchronous queue processing
I have a multi-threaded app where objects are enqueued by one thread and dequeued by the other (for sanity sake I'll call them the writer and reader threads).
The writer event is externally triggered and it is imperative that the trigger event is not delayed (which is why it is in its own thread).
There is an AutoResetEvent that is set to tell the reader thread that there are events to read. The problem is that if another writer event occurs while the reader is processing the queue it gives a System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
So - two questions:
(1) Is there a better architecture for this kind of situation
(2) If not, how do I prevent the error - i.e. how can the writer tell the reader to give is a rest for a while because more writing is going to be done?
(I could give code but it'd probably just confuse matters...)
-
Sep 20th, 2007, 03:58 PM
#2
Re: [VB2005] Asynchronous queue processing
What is this queue anyway? A List(of T)? Whatever it is, have you tried using SyncLock on it to assure that two threads are not trying to use it at the same time?
-
Sep 20th, 2007, 04:41 PM
#3
Re: [VB2005] Asynchronous queue processing
The queue is System.Collections.Queue
(Although I may change it to a Generic.Collections.Queue...)
The Queue class has some locking built in, i.e. an Enqueue and DeQueue operation block...but I may have to rewrite some of this because the writer must always have priority.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|