@@ -47,6 +47,7 @@ namespace CefSharp
4747 static Object^ _sync;
4848
4949 static bool _initialized = false ;
50+ static bool _hasShutdown = false ;
5051 static HashSet<IDisposable^>^ _disposables;
5152 static int _initializedThreadId;
5253 static bool _multiThreadedMessageLoop = true ;
@@ -91,12 +92,6 @@ namespace CefSharp
9192 {
9293 return _initialized;
9394 }
94-
95- private:
96- void set (bool value)
97- {
98- _initialized = value;
99- }
10095 }
10196
10297 // / <summary>Gets a value that indicates the version of CefSharp currently being used.</summary>
@@ -205,7 +200,7 @@ namespace CefSharp
205200 // / <returns>true if successful; otherwise, false.</returns>
206201 static bool Initialize (CefSettingsBase^ cefSettings, bool performDependencyCheck, IApp^ cefApp)
207202 {
208- if (IsInitialized )
203+ if (_initialized )
209204 {
210205 // NOTE: Can only initialize Cef once, to make this explicitly clear throw exception on subsiquent attempts
211206 throw gcnew Exception (" CEF can only be initialized once per process. This is a limitation of the underlying " +
@@ -215,6 +210,15 @@ namespace CefSharp
215210 " calling Cef.Initialize after you've created an instance of ChromiumWebBrowser, it must be before the first instance is created." );
216211 }
217212
213+ if (_hasShutdown)
214+ {
215+ // NOTE: CefShutdown has already been called.
216+ throw gcnew Exception (" Cef.Shutdown has already been called. CEF can only be initialized once per process. " +
217+ " This is a limitation of the underlying CEF/Chromium framework. Calling Cef.Initialize after Cef.Shutdown is not supported. "
218+ " You can change many (not all) settings at runtime through RequestContext.SetPreference." +
219+ " See https://github.com/cefsharp/CefSharp/wiki/General-Usage#request-context-browser-isolation" );
220+ }
221+
218222 // Empty string is acceptable, the main application executable will be used
219223 if (cefSettings->BrowserSubprocessPath == nullptr )
220224 {
@@ -486,11 +490,11 @@ namespace CefSharp
486490 // / </summary>
487491 static void Shutdown ()
488492 {
489- if (IsInitialized )
493+ if (_initialized )
490494 {
491495 msclr::lock l (_sync);
492496
493- if (IsInitialized )
497+ if (_initialized )
494498 {
495499 if (_initializedThreadId != Thread::CurrentThread->ManagedThreadId )
496500 {
@@ -529,7 +533,8 @@ namespace CefSharp
529533 }
530534
531535 CefShutdown ();
532- IsInitialized = false ;
536+ _initialized = false ;
537+ _hasShutdown = true ;
533538 }
534539 }
535540 }
@@ -545,14 +550,15 @@ namespace CefSharp
545550 // / </summary>
546551 static void ShutdownWithoutChecks ()
547552 {
548- if (IsInitialized )
553+ if (_initialized )
549554 {
550555 msclr::lock l (_sync);
551556
552- if (IsInitialized )
557+ if (_initialized )
553558 {
554559 CefShutdown ();
555- IsInitialized = false ;
560+ _initialized = false ;
561+ _hasShutdown = true ;
556562 }
557563 }
558564 }
@@ -869,7 +875,7 @@ namespace CefSharp
869875 return ;
870876 }
871877
872- if (IsInitialized )
878+ if (_initialized )
873879 {
874880 throw gcnew Exception (" Must be enabled before Cef.Initialize is called. " );
875881 }
0 commit comments