Beispiel #1
0
        private static bool ReloadAppDomain()
        {
            if (!GameThreadHelper.IsInGameThread())
            {
                bool result = false;
                GameThreadHelper.Run(delegate { result = ReloadAppDomain(); });
                return(result);
            }

            if (!File.Exists(assemblyPath))
            {
                hotreloadData = null;
                return(false);
            }

            if (appDomain != null)
            {
                UnloadAppDomain();
            }

            if (LoadAssemblyWithoutAppDomain)
            {
                try
                {
                    AssemblyLoader loader = new AssemblyLoader(assemblyPath, entryPointType, entryPointMethod, entryPointArg, hotreloadData, false);
                    loader.Load();
                }
                catch (Exception e)
                {
                    MessageBox.Show("Failed to load assembly \"" + assemblyPath + "\" " +
                                    Environment.NewLine + Environment.NewLine + e, errorMsgBoxTitle);
                    hotreloadData = null;
                    return(false);
                }
            }
            else
            {
                string entryPointArgEx = entryPointArg;
                bool   firstLoad       = preloadAppDomainWaitHandle == null;
                if (firstLoad)
                {
                    PreloadNextAppDomain(true);
                }
                else
                {
                    entryPointArgEx += "|Reloading=true";
                }

                preloadAppDomainWaitHandle.WaitOne(Timeout.Infinite);
                preloadAppDomainWaitHandle.Reset();

                if (!preloadFailed)
                {
                    appDomain        = preloadAppDomain;
                    preloadAppDomain = null;

                    try
                    {
                        AssemblyLoader loader = new AssemblyLoader(assemblyPath, entryPointType, entryPointMethod, entryPointArgEx, hotreloadData, false);
                        appDomain.DoCallBack(loader.Load);
                        UpdateAssemblyWatchers(appDomain.GetData(hotReloadAssemblyPathsName) as string[]);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Failed to create AppDomain for \"" + assemblyPath + "\" " +
                                        Environment.NewLine + Environment.NewLine + e, errorMsgBoxTitle);
                    }
                }
            }

            if (!LoadAssemblyWithoutAppDomain)
            {
                PreloadNextAppDomain(false);
            }
            hotreloadData = null;
            return(true);
        }
Beispiel #2
0
        private static bool ReloadMainContext(bool threaded = true)
        {
            if (!GameThreadHelper.IsInGameThread())
            {
                bool result = false;
                GameThreadHelper.Run(delegate { result = ReloadMainContext(); });
                return(result);
            }

            if (!SharedRuntimeState.IsActiveRuntime)
            {
                return(false);
            }

            if (!File.Exists(mainAssemblyPath))
            {
                SharedRuntimeState.SetHotReloadData(null);
                return(false);
            }

            if (!mainContextRef.IsInvalid)
            {
                UnloadMainContext(threaded);
            }

            string entryPointArgEx = entryPointArg;
            bool   firstLoad       = preloadContextWaitHandle == null;

            if (firstLoad)
            {
                PreloadNextContext(threaded);
            }
            else
            {
                entryPointArgEx += "|Reloading=true";
            }

            preloadContextWaitHandle.WaitOne(Timeout.Infinite);
            preloadContextWaitHandle.Reset();

            if (!preloadFailed)
            {
                Debug.Assert(!preloadedContextRef.IsInvalid, "Preloaded context shouldn't be invalid");

                mainContextRef      = preloadedContextRef;
                preloadedContextRef = Runtime.AssemblyContextRef.Invalid;

                entryPointArgEx += "|AssemblyContext=" + mainContextRef.Format();

                try
                {
                    AssemblyLoader loader = new AssemblyLoader(mainAssemblyPath, entryPointType, entryPointMethod, entryPointArgEx, false, mainContextRef);
                    mainContextRef.DoCallBack(loader.Load);
                    UpdateAssemblyWatchers();
                }
                catch (Exception e)
                {
                    MessageBox("Failed to create assembly context for \"" + mainAssemblyPath + "\" " +
                               Environment.NewLine + Environment.NewLine + e, errorMsgBoxTitle);
                }
            }

            PreloadNextContext(threaded);
            SharedRuntimeState.SetHotReloadData(null);
            return(true);
        }