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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Delegates, asynchronous invocation

Delegates, asynchronous invocation

Scheduled Pinned Locked Moved C#
helpcsharpdesignregexquestion
3 Posts 2 Posters 1 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.
  • S Offline
    S Offline
    Serge Lobko Lobanovsky
    wrote on last edited by
    #1

    Hi everyone, I've been stuck with this problem for several days already. My code extensively uses asynchronous delegate invocation using the Delegate.BeginInvoke method. The general pattern is as follows: Scheduler or UI thread: 1) BeginInvoke function 1 First function: 1) prepare data 2) BeginInvoke data processing passing CurrentThread (see below) 3) CurrentThread.Suspend 4) (after resume) go to step 1 with new data processing command, if all commands are executed, exit Data processing: 0) get calling thread (passed in parameters) 1) process data 2) set result 3) resume calling thread Several data processing commands (Command pattern) require asynchronous calls, too. That is that BeginInvoke method is called from inside another method which was called using BeginInvoke, too. What I've noticed so far is that sometimes the delegate being BeginInvoke'd is NOT CALLED AT ALL! To give more evidence, I have a special Logger class which sends messages to a text box. Apparently, it uses Control.BeginInvoke to correctly dispatch Text property changes. Sometimes again the function specified in MethodInvoker delegate is also NOT CALLED AT ALL! What could be the problem? I honestly hope it is not a bug in the framework, as the project is (and has been for the last month) in the final stage. Regards, Serge (Logic Software, Easy Projects .NET site)

    D 1 Reply Last reply
    0
    • S Serge Lobko Lobanovsky

      Hi everyone, I've been stuck with this problem for several days already. My code extensively uses asynchronous delegate invocation using the Delegate.BeginInvoke method. The general pattern is as follows: Scheduler or UI thread: 1) BeginInvoke function 1 First function: 1) prepare data 2) BeginInvoke data processing passing CurrentThread (see below) 3) CurrentThread.Suspend 4) (after resume) go to step 1 with new data processing command, if all commands are executed, exit Data processing: 0) get calling thread (passed in parameters) 1) process data 2) set result 3) resume calling thread Several data processing commands (Command pattern) require asynchronous calls, too. That is that BeginInvoke method is called from inside another method which was called using BeginInvoke, too. What I've noticed so far is that sometimes the delegate being BeginInvoke'd is NOT CALLED AT ALL! To give more evidence, I have a special Logger class which sends messages to a text box. Apparently, it uses Control.BeginInvoke to correctly dispatch Text property changes. Sometimes again the function specified in MethodInvoker delegate is also NOT CALLED AT ALL! What could be the problem? I honestly hope it is not a bug in the framework, as the project is (and has been for the last month) in the final stage. Regards, Serge (Logic Software, Easy Projects .NET site)

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Serge Lobko-Lobanovsky wrote: First function: 1) prepare data 2) BeginInvoke data processing passing CurrentThread (see below) 3) CurrentThread.Suspend 4) (after resume) go to step 1 with new data processing command, if all commands are executed, exit I've got a question. Why are you launching another thread and then pausing the current one, waiting for the newly launched thread to complete? There's no reason to launch another thread to do the work if your just going to sit around and wait for it to complete! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Serge Lobko-Lobanovsky wrote: First function: 1) prepare data 2) BeginInvoke data processing passing CurrentThread (see below) 3) CurrentThread.Suspend 4) (after resume) go to step 1 with new data processing command, if all commands are executed, exit I've got a question. Why are you launching another thread and then pausing the current one, waiting for the newly launched thread to complete? There's no reason to launch another thread to do the work if your just going to sit around and wait for it to complete! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        S Offline
        S Offline
        Serge Lobko Lobanovsky
        wrote on last edited by
        #3

        You're right. I am now simplifying the code. However, the proble is still there: I call Control.BeginInvoke(new MethodInvoker(myMethod)) and the debugger never stops in myMethod, and the code never executes. Regards, Serge (Logic Software, Easy Projects .NET site)

        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