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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:50:47+00:00 2026-05-25T10:50:47+00:00

I know this has been asked before , but I don’t think these solutions

  • 0

I know this has been asked before, but I don’t think these solutions are flexible. The DocumentCompleted event should be used to determine when the load has completed, not as a method for performing work. If you need to perform several different tasks that each have to navigate several times, placing the logic in the DocumentCompleted event turns it into a messy switch/case router that is hard to read and maintain.

You need something that can actually wait during your method performing navigation so you can continue your task in the method you are already in. My first though is an actual Wait() method.

I would think something like this is close:

void WaitForLoad()
    {
        isLoading = true;
        while (isLoading)
        {
            if (Application.Current == null) break;
            Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, (DispatcherOperationCallback)delegate(object unused) { return null; }, null);
        }
    }

And set Isloading to false in the DocumentCompleted event.

You should be able to just call this method after whatever action will cause a pageload. It works, it has some issues.

1) it sends the CPU usage for the app up to 35% until the page has loaded, even if nothing else is happening.

2) if the application tries to close while its running, the loop will keep running and leave the app open with no windows, hence the need for the break when the app is null.

Can this be fixed, or am I coming at this all the wrong way?

Edit: I tried implementing the ManualResetEvent solution below, but it led to several other issues that I am not sure can be resolved without creating a messier situation than the one above. Since the WebBrowser is on the UI, locking the thread stop the entire app. If the work is done on the background thread it can be locked, but then accessing the WebBrowser becomes very difficult.

  • 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-25T10:50:49+00:00Added an answer on May 25, 2026 at 10:50 am

    In your situation, it sounds like you want a specific thread to block while waiting for the document to load. In that case, you would do something like this:

      protected ManualResetEvent _resetEvent = new ManualResetEvent(false);
    
      public void WaitingThread()
      {
          _resetEvent.WaitOne();
    
          // Do stuff after the web browser completes. 
      }
    
      public void LoadWebPage()
      {
          webBrowser.Navigate(new Uri(url));
          webBrowser.DocumentCompleted = (s, e) => { _resetEvent.Set(); };
      }
    

    Basically, when the document completes, you signal the event and any threads waiting on the event unblock and continue executing.

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

Sidebar

Related Questions

I know this question has been asked here before, but I don't think those
I don't know if this has been asked before, but we're having a discussion
I don't think this has been asked before on this site, but I might
I don't know if this question has been asked before, but I'll go through
All- I know this has been asked, but the previous solutions don't seem to
I don't know if this has been asked before, but what i'd like to
I know this question has been asked before, but many answers don't give clear
Ok, I know this has been asked before but after searching I couldn't find
I know this has been asked before, but I've found a different way to
I know this question has been asked before, but I ran into a problem.

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.