Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with AutoResetEvent Array and WaitHandle.WaitAll()

Problem with AutoResetEvent Array and WaitHandle.WaitAll()

Scheduled Pinned Locked Moved C#
helpdata-structures
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FJJCENTU
    wrote on last edited by
    #1

    I am tryng to split a process in some methods stopping the methods with objects ManualResetEvent and AutoResetEvent but I am having problems with the WaitHandle.WaitAll() method with this method I want stop the proccess until everyone event is pointed, but I receive the error message of "Not valid WaitAll for various events in a STA proccess" Please ho can I solve the problem

    B G 2 Replies Last reply
    0
    • F FJJCENTU

      I am tryng to split a process in some methods stopping the methods with objects ManualResetEvent and AutoResetEvent but I am having problems with the WaitHandle.WaitAll() method with this method I want stop the proccess until everyone event is pointed, but I receive the error message of "Not valid WaitAll for various events in a STA proccess" Please ho can I solve the problem

      B Offline
      B Offline
      Bekjong
      wrote on last edited by
      #2

      Use Google. The first hit that comes up already provides a solution:

      private void WaitAll(WaitHandle[] waitHandles) {
      if (Thread.CurrentThread.ApartmentState == ApartmentState.STA) {
      // WaitAll for multiple handles on an STA thread is not supported.
      // ...so wait on each handle individually.
      foreach(WaitHandle myWaitHandle in waitHandles) {
      WaitHandle.WaitAny(new WaitHandle[]{myWaitHandle});
      }
      }
      else {
      WaitHandle.WaitAll(waitHandles);
      }
      }

      Standards are great! Everybody should have one!

      1 Reply Last reply
      0
      • F FJJCENTU

        I am tryng to split a process in some methods stopping the methods with objects ManualResetEvent and AutoResetEvent but I am having problems with the WaitHandle.WaitAll() method with this method I want stop the proccess until everyone event is pointed, but I receive the error message of "Not valid WaitAll for various events in a STA proccess" Please ho can I solve the problem

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        You can start a new thread, set its apartment state to MTA and call the WaitAll method there. Then just call Join on the thread. It is much better then using a foreach loop.

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups