title: How to properly initialize CefSharp web browser
body: <p>I am using the CefSharp web browser in my project. But when I switch between two WinForms I got this exception.</p>
  <blockquote>
  <p>System.Exception: 'CEF can only be initialized once per process. This is a limitation of the underlying CEF/Chromium framework. You can change many (not all) settings at runtime through RequestContext.SetPreference. See <a href="https://github.com/cefsharp/CefSharp/wiki/General-Usage#request-context-browser-isolation" rel="nofollow noreferrer">https://github.com/cefsharp/CefSharp/wiki/General-Usage#request-context-browser-isolation</a> Use Cef.IsInitialized to guard against this exception. If you are seeing this unexpectedly then you are likely calling Cef.Initialize after you've created an instance of ChromiumWebBrowser, it must be before the first instance is created.'</p>
  </blockquote>
  <p>Here is the code.</p>
  <pre><code>public ChromiumWebBrowser browser;
  
  
      public void InitBrowser()
      {
          Cef.Initialize(new CefSettings());
          browser = new ChromiumWebBrowser(Settings.Default.SetLink);
          this.GpBrwsr.Controls.Add(browser);
          browser.Dock = DockStyle.Fill;
      }
      public Form3()
      {
      
          InitBrowser();
      }
  
      private void browser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
      {
          if (e.IsLoading == false)
          {
              browser.ExecuteScriptAsync(&quot;alert('All Resources Have Loaded');&quot;);
          }
      }
  </code></pre>
  <p>And here is how i am switching between forms.</p>
  <pre><code>LoginToSettings Login = new LoginToSettings();
  Login.Show();
  this.Hide();
  </code></pre>
  <p><a href="https://i.stack.imgur.com/nP1sN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nP1sN.png" alt="Exception Image" /></a></p>
  <p>My question is how do I initialize it so I don't stumble upon this exception?
  I also tried &quot;Form Minimization&quot; Option instead of &quot;Form Hiding&quot;
  But still the same issue.</p>
  <p>I have used this link for using CefSharp browser.
  <a href="https://www.telerik.com/support/kb/winforms/details/how-to-embed-chrome-browser-in-a-winforms-application" rel="nofollow noreferrer">Code Source for CefSharp</a></p>