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 8627603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:19:20+00:00 2026-06-12T08:19:20+00:00

I searched in google for a method which allows me to display a label

  • 0

I searched in google for a method which allows me to display a label for a specific time and I found this :

public void InfoLabel(string value)
        {
            if (InvokeRequired)
            {
                this.Invoke(new Action<string>(InfoLabel), new object[] { value });
                return;
            }
            barStaticItem3.Caption = value;

            if (!String.IsNullOrEmpty(value))
            {
                System.Timers.Timer timer = new System.Timers.Timer(6000) { Enabled = true };
                timer.Elapsed += (sender, args) =>
                {
                    this.InfoLabel(string.Empty);
                    timer.Dispose();
                };
            }

        }

I really can’t understand this method specially :

-Why we used : InvokeRequired ?

-What this method for : this.Invoke() ?

-What this is for :new Action<string>(InfoLabel) ?

-Why we used that sign : => ?

  • 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. Editorial Team
    Editorial Team
    2026-06-12T08:19:21+00:00Added an answer on June 12, 2026 at 8:19 am

    InvokeRequired checks to see if the code is currently running on the thread that created the form. If it’s not then the function needs to invoke itself on the thread that DID create the form as WinForms code is not threadsafe.

    Action is a delegate type that describes a function that takes a string (see the InfoLabel funcion? That’s what it’s referring to).

     this.Invoke(new Action<string>(InfoLabel), new object[] { value });
    

    The above is saying. Please create a new delegate of type Action from the function InfoLabel and invoke it using the thread that created this. When you invoke it pass the object ‘value’ to it. ie call InfoLabel(value) on the thread that created the form. Notice that it returns from the function directly afterwards so none of the ‘meat’ of the function is run on the wrong thread (we are on the wrong thread at this point, otherwise InvokeRequired would not have been true). When the function is run again by Invoke it will be on the right thread and InvokeRequired will be false so this bit of code will not be run.

    timer.Elapsed += (sender, args) =>
                    {
                        this.InfoLabel(string.Empty);
                        timer.Dispose();
                    };
    

    The above code is assigning an anonymous method to the Elapsed event of the timer. The first bit (sender, args) is describing the parameters of the method, then => is saying ‘here comes the method’, followed by a block of code (all the stuff inside the brackets).

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

Sidebar

Related Questions

i have searched on google but not able to know which event/method is called
I've searched google and SO for a solution to this problem but have not
I have searched google and exhausted a fair bit of my time trying to
I have searched around Google and StackOverflow trying to find a solution to this,
Disclaimer: i have searched genericly (Google) and here for some information on this topic,
I've searched around on SO, and found a few questions that ask about this,
I searched Google search APIs and didn't find a way to get a website
I've searched Google for awhile now, doesn't seem like I am correctly searching it
I searched in Google to find the differences between a case class and a
I have searched on google about how to get started with the dependency property

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.