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

  • Home
  • SEARCH
  • 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 7090857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:06:30+00:00 2026-05-28T08:06:30+00:00

The first topic is What wrong with my InvokeRequied I followed the answer that

  • 0

The first topic is What wrong with my InvokeRequied

I followed the answer that he recommended it to me but I found a new problem.

The result of below picture is cross thread exception.

What is wrong with my code ?

How to solve this problem ?

enter image description here

  • 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-05-28T08:06:31+00:00Added an answer on May 28, 2026 at 8:06 am

    According to MSDN InvokeRequired can return false even in cases where InvokeRequired should be true – namely in the case that you access InvokeRequired before the Handle of that control/form (or a parent of it) has been created.

    Basically your check is incomplete which leads to the result you see.

    You need to check IsHandleCreated – if that is false then you would need to use Invoke/BeginInvoke regardless of what InvokeRequired returns.

    [UPDATE]
    BUT:
    This usually won’t work robustly since Invoke/BeginInvoke check which thread created Handle to do their magic…
    [/UPDATE]

    Only if IsHandleCreated is true you act based on what InvokeRequired returns – something along the lines of:

    if (control.IsHandleCreated)
    {
        if (control.InvokeRequired)
        {
            control.BeginInvoke(action);
        }
        else
        {
            action.Invoke();
        }
    }
    else 
    { 
        // in this case InvokeRequired might lie - you need to make sure that this never happens! 
        throw new Exception ( "Somehow Handle has not yet been created on the UI thread!" );
    }
    

    [UPDATE]

    Thus the following is important to avoid this problem

    Always make sure that the Handle is already created BEFORE the first access on a thread other than the UI thread.

    According to MSDN you just need to reference control.Handle in the UI thread to force it being created – in your code this must happen BEFORE the very first time you access that control/form from any thread that is not the UI thread.

    [/UPDATE]

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

Sidebar

Related Questions

That is my first topic here.i hope you can help me. I don't know
First of all, i am new to this topic, and after gathering a lot
WHY?! ... Maybe that's your first thought when reading the headline of this topic.
I'm here again with another question/problem. I know that topic's title may be like
First of all, excuse my poor topic title. I simply have no idea how
It's my first question on SO. I know that there were many topics on
First of all, I know how to build a Java application. But I have
First let me say that I really feel directionless on this question. I am
First of all: yes, I read all the other threads on this topic. And
I know there are a lot of questions on this topic already, but it

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.