Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 151379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:26:25+00:00 2026-05-11T09:26:25+00:00

I have gotten a bit lazy(it’s sometimes good) and started updating WinForms UI by

  • 0

I have gotten a bit lazy(it’s sometimes good) and started updating WinForms UI by invoking a callback without checking InvokeRequired first.

Are there a performance issues or considerations that I should be aware of?

    private delegate void SetStatusEventHandler(string statusMessage);     private void SetStatus(string statusMessage)     {         Invoke((MethodInvoker) (() =>         {             resultLabel.Text = statusMessage;         }));          //  - vs -          if (InvokeRequired)         {             SetStatusEventHandler cb = SetStatus;             Invoke(cb, statusMessage);         }         else         {             resultLabel.Text = statusMessage;         }     } 

[EDIT]: Most of times that a method that calls ‘invoke’ will be called at most like say 10~20 times a second with a wide interval inbetween.

[UPDATE] Settled with the following extension method

public static class SmartInvoker {     public static void InvokeHandler(this Control control, MethodInvoker del)     {         if (control.InvokeRequired)         {             control.Invoke(del);             return;         }         del();     } }  ...      private void SetStatus(string statusMessage)     {         this.InvokeHandler(() => resultLabel.Text = statusMessage);     } 

I guess finding out how to manage extension method classes is another topic I need to dig in. Thank you for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:26:26+00:00Added an answer on May 11, 2026 at 9:26 am

    EDIT: See the comments for debate about the whole posting vs immediately dispatching malarky.

    Either way, my answer is actually the same: unless this is happening hugely often unnecessarily (i.e. most of the time you’re on the UI thread to start with, and it’s attached to something like a mouse movement handler) I wouldn’t worry. It certainly makes the code simpler. If this is going to be invoked very often, I’d measure and test more 🙂

    Invoke is faster with an EventHandler or MethodInvoker delegate than with others. I don’t know if there’s any difference between the two – you may want to check.

    You can make this even simpler by writing an extension method, e.g.

    public static void InvokeHandler(this Control control, MethodInvoker handler) {      control.Invoke(handler); } 

    Then you can make your code:

    private void SetStatus(string statusMessage) {     this.InvokeHandler(delegate     {         resultLabel.Text = statusMessage;     }); } 

    or

    private void SetStatus(string statusMessage) {     InvokeHandler(() => resultLabel.Text = statusMessage); } 

    That way you don’t need to specify the delegate type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have gotten everything working for my class in which I am using Tomcat
I have been searching everywhere for the following functionality in Lisp, and have gotten
I am working on Conway's Game of Life currently and have gotten stuck. My
I've searched for this a little but I have not gotten a particularly straight
I guess the topic says it. I have tried googling this, but havent gotten
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a shell script that I want to set uid bit. I set
I have a little trouble understanding the security bit around JSON, because often things
I'm following the MVC Music Store tutorial, but I've just gotten a bit stuck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.