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. How expensive is Invoke?

How expensive is Invoke?

Scheduled Pinned Locked Moved C#
designquestion
3 Posts 3 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.
  • A Offline
    A Offline
    Arun Bhalla
    wrote on last edited by
    #1

    I want to use Control.Invoke to interact between the UI thread and other threads. In some cases, I expect I might need to make thousands of Invoke calls in a short period of time. How expensive is Invoke? Might I be better off optimizing by grouping together data so I don't have to make many Invoke calls, or is it nothing to worry about?

    L J 2 Replies Last reply
    0
    • A Arun Bhalla

      I want to use Control.Invoke to interact between the UI thread and other threads. In some cases, I expect I might need to make thousands of Invoke calls in a short period of time. How expensive is Invoke? Might I be better off optimizing by grouping together data so I don't have to make many Invoke calls, or is it nothing to worry about?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Control.Invoke itself is not expensive. Using Reflection to invoke a function is. But you are not using reflection. So the answer is: Not expensive. (unless you want to send me money) ;P I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

      1 Reply Last reply
      0
      • A Arun Bhalla

        I want to use Control.Invoke to interact between the UI thread and other threads. In some cases, I expect I might need to make thousands of Invoke calls in a short period of time. How expensive is Invoke? Might I be better off optimizing by grouping together data so I don't have to make many Invoke calls, or is it nothing to worry about?

        J Offline
        J Offline
        Jeff J
        wrote on last edited by
        #3

        Adequate efficiency is not usually something that can be predicted, so you might just have to test things. However, even if you were not making cross-thread calls, thousands of calls in a short period of time (say milliseconds) is not as efficient as batching some data together. This would be especially true if each call only passes a small amount of data. Cross-thread calls will add to execution time, but may or may not be the crucial factor. If things aren't happening as fast as you'd like, it can't hurt to try batching some data together. Also, keep in mind that Invoke() is synchronous, so each call will wait for completion. BeginInvoke() might be worth looking at, since it is asynchrous, and will return immediately. However, it might be less attractive if the data needs to be synchronised. Which one to use really depends on the particular situation. Cheers

        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