Created
August 2, 2017 05:28
-
-
Save Jadd/e2e389d6c26446ac01bfdf8beb733507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Bootstrap { | |
#region Fields | |
private static AppDomain _domain; | |
private static readonly object _domainLock = new object(); | |
#endregion | |
#region Exports | |
[DllExport("Initialize", CallingConvention.Winapi)] | |
public static void Export_Initialize() => Initialize(); | |
[DllExport("Shutdown", CallingConvention.Winapi)] | |
public static void Export_Shutdown() => Shutdown(); | |
#endregion | |
public static void Initialize() { | |
lock(_domainLock) { | |
if (_domain != null) | |
Shutdown(); | |
var currentAssembly = Assembly.GetExecutingAssembly(); | |
var currentPath = Path.GetDirectoryName(currentAssembly.Location); | |
var appDomainSetup = new AppDomainSetup { | |
ApplicationBase = currentPath, | |
ShadowCopyFiles = "true" | |
}; | |
_domain = AppDomain.CreateDomain("Aria.Internal", null, appDomainSetup); | |
_domain.DoCallBack(InternalInitialize); | |
} | |
} | |
public static void Shutdown() { | |
lock(_domainLock) { | |
if (_domain == null) | |
return; | |
_domain.DoCallBack(InternalShutdown); | |
AppDomain.Unload(_domain); | |
_domain = null; | |
} | |
} | |
private static void InternalInitialize() { | |
if (Engine.Initialized) | |
return; | |
Window.Initialize(); | |
Context.Dispatch(Engine.Initialize); | |
} | |
private static void InternalShutdown() { | |
if (!Engine.Initialized) | |
return; | |
Context.Dispatch(Engine.Shutdown); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment