0

For my Web Browser, I need a way to show if a page is loading. So I used this code

private void ChromiumWebBrowser1_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
    {
        if (bunifuCards1.Contains(bunifuLoader1))
        {
            if (e.IsLoading)
            {
                bunifuLoader1.BringToFront();
            }
            else
            {
                bunifuImageButton4.BringToFront();
            }
        }
    }

But it gave me this error on bunifuLoader1.BringToFront();

System.InvalidOperationException: 'Cross-thread operation not valid: Control 'bunifuLoader1' accessed from a thread other than the thread it was created on.'

This exception was originally thrown at this call stack:
System.Windows.Forms.Control.Handle.get()
System.Windows.Forms.Control.UpdateChildZOrder(System.Windows.Forms.Control)
System.Windows.Forms.Control.UpdateZOrder()
System.Windows.Forms.Control.ControlCollection.SetChildIndexInternal(System.Windows.Forms.Control, int)
System.Windows.Forms.Control.ControlCollection.SetChildIndex(System.Windows.Forms.Control, int)
System.Windows.Forms.Control.BringToFront()
World_Search_8_Goldsmith.frmBrowser.ChromiumWebBrowser1_LoadingStateChanged(object, CefSharp.LoadingStateChangedEventArgs) in frmBrowser.cs
CefSharp.WinForms.ChromiumWebBrowser.CefSharp.Internals.IWebBrowserInternal.SetLoadingStateChange(CefSharp.LoadingStateChangedEventArgs) in ChromiumWebBrowser.Partial.cs
CefSharp::Internals::ClientAdapter::OnLoadingStateChange(scoped_refptr<CefBrowser>*, bool, bool, bool) in ClientAdapter.cpp

Can some plz help me

  • First lines in [the docs](https://cefsharp.github.io/api/63.0.0/html/E_CefSharp_Wpf_ChromiumWebBrowser_LoadingStateChanged.htm#:~:text=%EE%80%80ChromiumWebBrowser.%20LoadingStateChanged%EE%80%81%20Event.%20Version%2063.0.0.%20Event%20handler%20that,is%20terminated%20due%20to%20completion%2C%20cancellation%20of%20failure.): _It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI thread._ – Steve Nov 25 '21 at 16:19
  • For a possible solution look at https://stackoverflow.com/questions/142003/cross-thread-operation-not-valid-control-accessed-from-a-thread-other-than-the – Steve Nov 25 '21 at 16:21

0 Answers0