none
AsyncOperation.Post isn't Posting, due to Form.Control.InvokeRequired... RRS feed

  • Question

  • Anyone who has read my other threads can skip through the preamble regarding the StayAliveThread. 

    StayAliveThread:

    THis is a Looping thread using a Wait and Pulse to queue up the thread proc.  Thus, I have a Command Object that contains this thread object.  When I Call: Command.ExecuteAsync() the ThreadProc() method is pushed into the queue for the StayAliveThread and a Pulse() is sent to wake up the thread loop, which executes the ThreadProc() from the queue.  Prior to pushing the ThreadProc() into the queue and the subsequent Pulse(), i create an AsyncOperation object, that is rooted in the Calling thread.  I use this AsyncOperation to Post back the Completion and Progress events.

    My App:
    Now, I have a simple form where i enter in a web site (imdb.com episode list for a tv show).  I execute my WebClient which uses the AsyncCommand to download the web page, and using the mshtml.HTMLDocument i parse the document and get the Episode names and URLs. 

    THis is where I'm having the problem:
    When I execute the cycle of the Episode pages, it loads the first page, and everything is fine.  In the AsyncOperation.PostCompletedOperation() call, i post back to the UI thread a complete event, which triggers the parsing engine of the current Episode page, getting say, the director name for that TV Show Episode.  I then increment the Episode number and load the Next episode page.  Loading the Next episode page, creates a new AsyncOperation class, and starts the process of downloading the next URL, but at this point I get a Cross-thread exception due to the progressbar suddenly having InvokeRequired as true.  Why?  I'm always executing from the ui thread and posting back to the ui thread so where is the cross-thread error?

    Flow:
    1. LoadNextEpisode()
    2. Navigate()
    3. Command.ExecuteAsync()
    4. Create AsyncOperation Object for Current Thread
    5. Repeat: AsyncOperation.Post(Progress)
    6. AsyncOperation.PostCompletedOperation(Complete)
    7. UICompleteEventMethodHandler()
    8. ParseDocument()
    9. LoadNextExpisode() //Back to 1.  When it reaches the last episode it exist and does not call LoadNextEpisode)
    So given that flow, is the fact that I'm calling the Second LoadNextEpisode from the path Async.Post -> Complete -> Parse making the application assume that the second call to command.ExecuteAsync() is on the first executions thread path?

    Thanks
    Jaeden "Sifo Dyas" al'Raec Ruiner

     
    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
    Wednesday, March 3, 2010 5:04 PM

Answers

  • The simle solution ? Just check for progressbar.InvokeRequired  for 'true' everytime or you want to go into WinDBG and read hex values from the stack ?

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off (c) — Bjarne Stroustrup [http://www2.research.att.com/~bs/bs_faq.html#really-say-that]
    • Marked as answer by eryang Monday, March 15, 2010 3:44 AM
    Monday, March 8, 2010 2:20 PM

All replies

  • The simle solution ? Just check for progressbar.InvokeRequired  for 'true' everytime or you want to go into WinDBG and read hex values from the stack ?

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off (c) — Bjarne Stroustrup [http://www2.research.att.com/~bs/bs_faq.html#really-say-that]
    • Marked as answer by eryang Monday, March 15, 2010 3:44 AM
    Monday, March 8, 2010 2:20 PM
  • The simle solution ? Just check for progressbar.InvokeRequired  for 'true' everytime or you want to go into WinDBG and read hex values from the stack ?

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off (c) — Bjarne Stroustrup [http://www2.research.att.com/~bs/bs_faq.html#really-say-that]

    It was beyond my thought. OK. I'll take a try. Thanks very much.
    Friday, July 30, 2010 1:00 AM