Loading ...
Sorry, an error occurred while loading the content.

RE: [PowerThreading] Semantic of WaintHandle from AsyncEnumerator.BeginExecute's AsyncResult

Expand Messages
  • Jeffrey Richter (Wintellect LLC)
    I cannot repro the problem you describe. I just wrote this: var ae = new AsyncEnumerator(); IAsyncResult ar = ae.BeginExecute(Foo(ae), null, null);
    Message 1 of 2 , Aug 4, 2009
    View Source
    • 0 Attachment

      I cannot repro the problem you describe.

      I just wrote this:

            var ae = new AsyncEnumerator();

            IAsyncResult ar = ae.BeginExecute(Foo(ae), null, null);

            ar.AsyncWaitHandle.WaitOne();

            ae.EndExecute(ar);

       

          private static IEnumerator<Int32> Foo(AsyncEnumerator ae) {

              yield return 1;

          }

       

      And WaitOne blocks forever proving that the event is NOT signaled. I can’t explain the results your’re seeing.

      The code you show looks right to me however I would suggest NOT disposing of the handle; my code will do then when EndExecute is called.

      -- Jeffrey Richter (http://Wintellect.com)

       

      From: PowerThreading@yahoogroups.com [mailto:PowerThreading@yahoogroups.com] On Behalf Of evilshrike
      Sent: Tuesday, August 04, 2009 10:23 AM
      To: PowerThreading@yahoogroups.com
      Subject: [PowerThreading] Semantic of WaintHandle from AsyncEnumerator.BeginExecute's AsyncResult

       

       

      Hello.

      I have some my component which uses AsynEnumerator internally and this component contains some method:
      public void DoWork()
      {
      m_asyncEnumerator = new AsyncEnumerator();
      m_asyncEnumerator.BeginExecute(
      doRealWork(), m_asyncEnumerator.EndExecute);
      }
      it's very straightforward.
      Now I want the method DoWork returns a WaitHandle which could be used by client to wait for a result.
      (sure I could create BeginDoWork and EndDoWork, but I prefer WaitHandle)
      It's correct, isn't?

      So I'm changing the method to:
      public WaintHandle DoWork()
      {
      m_asyncEnumerator = new AsyncEnumerator();
      return m_asyncEnumerator.BeginExecute(
      doRealWork(),
      m_asyncEnumerator.EndExecute).AsyncWaitHandle;
      }
      Is it still correct?

      Then I try to use the new method:

      using (WaitHandle wh = component.DoWork())
      {
      wh.WaitOne();
      }
      Assert.IsTrue(component.IsCompleted) // check state

      The thing is that after WaitHandle signals it's complete component's doRealWork is not complete. It seems that WaitHandle (received from AsyncEnumerator.BeginExecute's AsyncState ) signals right after first "yield return 1".
      Is it by design? What is semantic of WaitHandle in AsyncResult from AsyncEnumerator.BeginExecute call?

    • evilshrike
      Sorry for this. I tried to delete the post. And it seemed to be deleted but not.
      Message 2 of 2 , Aug 6, 2009
      View Source
      • 0 Attachment
        Sorry for this. I tried to delete the post. And it seemed to be deleted but not.
      Your message has been successfully submitted and would be delivered to recipients shortly.