public void Dispose()
        {
            if (MyMultiplayer.Static != null)
                MyMultiplayer.Static.Dispose();

            if (GameRenderComponent != null)
            {
                GameRenderComponent.Dispose();
                GameRenderComponent = null;
            }
            MyPlugins.Unload();

            Parallel.Scheduler.WaitForTasksToFinish(TimeSpan.FromSeconds(10));
            m_windowCreatedEvent.Dispose();
        }
        public void Dispose()
        {
#if !XB1
            if (MySessionComponentExtDebug.Static != null)
            {
                MySessionComponentExtDebug.Static.Dispose();
                MySessionComponentExtDebug.Static = null;
            }
#endif // !XB1

            if (MyMultiplayer.Static != null)
                MyMultiplayer.Static.Dispose();

            if (GameRenderComponent != null)
            {
                GameRenderComponent.Dispose();
                GameRenderComponent = null;
            }
#if !XB1 // XB1_ALLINONEASSEMBLY
            MyPlugins.Unload();
#endif // !XB1

            Parallel.Scheduler.WaitForTasksToFinish(TimeSpan.FromSeconds(10));
            m_windowCreatedEvent.Dispose();

#if !XB1
            if (MyFakes.ENABLE_ROSLYN_SCRIPTS)
                MyScriptCompiler.Static.Whitelist.Clear();
            else
                IlChecker.Clear();
#endif

            Services = null;
            MyObjectBuilderType.UnregisterAssemblies();
            MyObjectBuilderSerializer.UnregisterAssembliesAndSerializers();
        }
        public MySandboxGame(VRageGameServices services, string[] commandlineArgs)
        {
            ParseArgs(commandlineArgs);
            ProfilerShort.Begin("MySandboxGame()::constructor");
            MySandboxGame.Log.WriteLine("MySandboxGame.Constructor() - START");
            MySandboxGame.Log.IncreaseIndent();

            Services = services;

            SharpDX.Configuration.EnableObjectTracking = MyCompilationSymbols.EnableSharpDxObjectTracking;

            UpdateThread = Thread.CurrentThread;

            // we want check objectbuilders, prefab's configurations, gameplay constants and building specifications
            ProfilerShort.Begin("Checks");

            MySandboxGame.Log.WriteLine("Game dir: " + MyFileSystem.ExePath);
            MySandboxGame.Log.WriteLine("Content dir: " + MyFileSystem.ContentPath);

            ProfilerShort.BeginNextBlock("MyCustomGraphicsDeviceManagerDX");

            Static = this;

            Console.CancelKeyPress += Console_CancelKeyPress;

            ProfilerShort.BeginNextBlock("InitNumberOfCores");
            InitNumberOfCores();

            ProfilerShort.BeginNextBlock("MyTexts.Init()");
            MyLanguage.Init();

            MySession.OnReady += delegate
            {
                if (OnSessionReady != null)
                    OnSessionReady();
            };

            ProfilerShort.BeginNextBlock("MyDefinitionManager.LoadScenarios");
            MyDefinitionManager.Static.LoadScenarios();

            ProfilerShort.BeginNextBlock("Preallocate");
            Preallocate();

            if (!IsDedicated)
            {
                ProfilerShort.BeginNextBlock("new MyGameRenderComponent");
                GameRenderComponent = new MyGameRenderComponent();
            }
            else
            {
                ProfilerShort.BeginNextBlock("Dedicated server setup");
                MySandboxGame.ConfigDedicated.Load();
                //ignum
                //+connect 62.109.134.123:27025

                IPAddress address = MyDedicatedServerOverrides.IpAddress ?? IPAddressExtensions.ParseOrAny(MySandboxGame.ConfigDedicated.IP);
                ushort port = (ushort)(MyDedicatedServerOverrides.Port ?? MySandboxGame.ConfigDedicated.ServerPort);

                IPEndPoint ep = new IPEndPoint(address, port);

                MyLog.Default.WriteLineAndConsole("Bind IP : " + ep.ToString());

                MyDedicatedServer dedicatedServer = new MyDedicatedServer(ep);
                MyMultiplayer.Static = dedicatedServer;

                FatalErrorDuringInit = !dedicatedServer.ServerStarted;

                if (FatalErrorDuringInit && !Environment.UserInteractive)
                {
                    var e = new Exception("Fatal error during dedicated server init: " + dedicatedServer.ServerInitError);
                    e.Data["Silent"] = true;
                    throw e;
                }
            }

            // Game tags contain game data hash, so they need to be sent after preallocation
            if (IsDedicated && !FatalErrorDuringInit)
            {
                (MyMultiplayer.Static as MyDedicatedServer).SendGameTagsToSteam();
            }

            ProfilerShort.BeginNextBlock("InitMultithreading");

            InitMultithreading();

            ProfilerShort.End();

            if (!IsDedicated && SteamSDK.SteamAPI.Instance != null)
            {
                SteamSDK.SteamAPI.Instance.OnPingServerResponded += ServerResponded;
                SteamSDK.SteamAPI.Instance.OnPingServerFailedToRespond += ServerFailedToRespond;
                SteamSDK.Peer2Peer.ConnectionFailed += Peer2Peer_ConnectionFailed;
            }

            MyMessageLoop.AddMessageHandler(MyWMCodes.GAME_IS_RUNNING_REQUEST, OnToolIsGameRunningMessage);

            MySandboxGame.Log.DecreaseIndent();
            MySandboxGame.Log.WriteLine("MySandboxGame.Constructor() - END");
            ProfilerShort.End();
        }
        public void Dispose()
        {
            if (MyMultiplayer.Static != null)
                MyMultiplayer.Static.Dispose();

            if (GameRenderComponent != null)
            {
                GameRenderComponent.Dispose();
                GameRenderComponent = null;
            }
            MyPlugins.Unload();

            Parallel.Scheduler.WaitForTasksToFinish(TimeSpan.FromSeconds(10));
            m_windowCreatedEvent.Dispose();


            IlChecker.Clear();

            Services = null;
            MyObjectBuilderType.UnregisterAssemblies();
            MyObjectBuilderSerializer.UnregisterAssembliesAndSerializers();
        }