Skip to content

Instantly share code, notes, and snippets.

@Jadd
Created August 2, 2017 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jadd/e2e389d6c26446ac01bfdf8beb733507 to your computer and use it in GitHub Desktop.
Save Jadd/e2e389d6c26446ac01bfdf8beb733507 to your computer and use it in GitHub Desktop.
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