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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:08:26+00:00 2026-06-14T00:08:26+00:00

Given Action closeLoadingAction = new Action(() => { loadingForm.Close(); #region – may need to

  • 0

Given

Action closeLoadingAction = new Action(() =>
{
  loadingForm.Close();
  #region - may need to put into second Action
  panelOnMainForm.Controls.AddRange(physdocControls.ToList<Control>().ToArray());
  if (Handle != IntPtr.Zero)
    User32DLL.SetForegroundWindow(this.Handle);//Handle is a property of the mainForm.
  #endregion
});

Sometimes I get handle not created exceptions even though I check the Invoke required.

if(loadingForm.InvokeRequired)
   loadingForm.Invoke(closeLoadingAction);
else
   closeLoadingAction();

The loading form runs on the same thread as the main form. The code you see above runs in a seperate thread. I suspect that I need another check for invoke against the main form. Do I need a second check or is what I have already safe?

  • 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-14T00:08:27+00:00Added an answer on June 14, 2026 at 12:08 am

    The code you see above runs in a seperate thread

    Using InvokeRequired like this when you know that the code runs on another thread is a bad anti-pattern. You can do much more useful things with it. Like:

    if (!loadingForm.InvokeRequired) {
        throw new InvalidOperationException("Threading race detected");
    }
    loadingForm.Invoke(closeLoadingAction);
    

    Or the more practical one if you meant to start the loading thread before the loading form’s Load event fired:

    while (!loadingForm.InvokeRequired) Thread.Sleep(50);
    loadingForm.Invoke(closeLoadingAction);
    

    Or just do it the right way and have the form’s Load event start the thread.

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

Sidebar

Related Questions

Given a table action(start:DATE, length:NUMBER, type:NUMBER), with all records unique, I need to select
Given the following statement lambda example: var fMyAction = new Action(() => { x
Is there a way to build a new timer with a given action, but
I want to redirect my '/' uri to a given controller's action. I used
Given an app (your app) and a certain action it has, is it possible
Given some typical search form, I can't construct this form action when submitting a
Given a particular URL, how do I find out for sure which controller action
In my controller i had given [ValidateInput(false)] for that particular Action in my return
Given this in a grails action: def xml = { rss(version: '2.0') { ...
Given a table custid | date | action 1 | 2011-04-01 | activate 1

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.