Results 1 to 3 of 3

Thread: [VB2005] Asynchronous queue processing

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    [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...)

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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
  •  



Click Here to Expand Forum to Full Width