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. assync call returns on wrong thread

assync call returns on wrong thread

Scheduled Pinned Locked Moved C#
question
3 Posts 2 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.
  • O Offline
    O Offline
    OmegaSupreme
    wrote on last edited by
    #1

    When you assynchronously invoke a delegate using begin invoke, much to my dismay the AsyncCallback it calls when finished is called on the wrong thread. The AsyncCallback is called on the same thread the assync processessing was done in. This is very annoying :mad::mad: What I need is for the main thread to be notified, so that from the callback method I can then call a method on the main thread. Anyone figured out how you can do this ???

    D 1 Reply Last reply
    0
    • O OmegaSupreme

      When you assynchronously invoke a delegate using begin invoke, much to my dismay the AsyncCallback it calls when finished is called on the wrong thread. The AsyncCallback is called on the same thread the assync processessing was done in. This is very annoying :mad::mad: What I need is for the main thread to be notified, so that from the callback method I can then call a method on the main thread. Anyone figured out how you can do this ???

      D Offline
      D Offline
      David Stone
      wrote on last edited by
      #2

      Go read this article. Even if you aren't working with a UI on the main thread, the techniques still apply.


      Hawaian shirts and shorts work too in Summer. People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage... -Anna-Jayne Metcalfe on Paintballing

      O 1 Reply Last reply
      0
      • D David Stone

        Go read this article. Even if you aren't working with a UI on the main thread, the techniques still apply.


        Hawaian shirts and shorts work too in Summer. People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage... -Anna-Jayne Metcalfe on Paintballing

        O Offline
        O Offline
        OmegaSupreme
        wrote on last edited by
        #3

        Hi David, Thanks for the link, it was very interesting. However I still cant see how the parent thread can be called when you are not working with windows forms, for example if you are working in a console app. I myself am specifically working with a class instantiated from the main form but not the main form itself. I tried inheriting from Control but this didnt work. What I need is the equivalent of Control.BeginInvoke but which can be used outside a form. Is it impossible ?

        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