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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:11:22+00:00 2026-06-01T15:11:22+00:00

I read a few threads about the MainWindowHandle but i couldnt find a solution

  • 0

I read a few threads about the MainWindowHandle but i couldnt find a solution for my problem, i’m starting a gui application and want to get the MainWindowHandle through the process object, but the handle value is always zero if i’m not going to wait with thread.sleep() until the gui is loaded. i’m also tried to use WaitForInputIdle but it didnt help at all.

process.Start();

process.WaitForInputIdle(1000);
while (process.MainWindowHandle == IntPtr.Zero)
{
     Thread.Sleep(100);
}
// do something with the handle

he is never leaving the while, if i’m replacing the waitforinputidle with a normal thread.sleep he gets the handle right.

to put it in simply words: i only want to continue with my code if i get a handle != zero but i dont want to wait a static time for this

  • 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-01T15:11:23+00:00Added an answer on June 1, 2026 at 3:11 pm

    The value stored in MainWindowHandle is cached. Add a process.Refresh() within your loop to invalidate that value:

    while (process.MainWindowHandle == IntPtr.Zero)
    {
        Thread.Sleep(100);
        process.Refresh();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read a few threads on StackOverflow about this, but cannot get it
Apologies for the long post -- Read a few threads about this, but still
I've read a few articles talking about checkboxes always returning a false state, but
I've read several threads about this topic and need some clarification on a few
I've read a few threads on SO about usefulness of unit-testing various applications. The
Hey, There's a lot of posts on here about read barcodes but I want
I know there's tons of threads about this. And I read a few of
I have read few good articles about NHibernate localization but nothing seems to fit
I've read through a few other threads on here, though none of them really
I read a few websites and questions but all were far beyond my level

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.