My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

Stop the webpage navigation in BeforeRequestLoad using dispatcher Options
Posted: Thursday, March 26, 2020 6:43:13 AM
Rank: Newbie
Groups: Member

Joined: 3/10/2020
Posts: 6
We have a scenario to stop OR continue to load the webpage based on a condition for which we registered for BeforeReqLoad event and set e.Canceled = true. As the event got invoked in a background thread, we had to invoke the condition in a Dispatcher(.Invoke). We would like to know if this has any impact in the sequence of loading the webpage. Please advise.

Below is the code snippet.
webView_BeforeReqLoad(object sender, EO.WebBrowser.BeforeRequestLoadEventArgs e)
 bool canceled=false;
            if (this.Dispatcher.CheckAccess())
              NavigatetoWPFView(ref canceled);  //call the method to open the WPF scree(canceled is set to true to stop the webpage navigation)
                    e.Canceled = canceled;
                System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
                    webView_BeforeReqLoad(sender, e);
Posted: Thursday, March 26, 2020 2:05:14 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 22,032

You can not do it this way. The reason that BeforeRequestLoad is called in a worker thread is because this event blocks the browser engine's IO thread thus is very performance sensitive, and any improper handling of this event can cause the browser engine to hang. If you choose to reroute the call to the UI thread, that would defeats the very purpose of triggering this event in a background thread. You should change your NavigateToWPFView method to be thread safe instead.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.