public RadegastInstance(GridClient client0)
        {
            // incase something else calls GlobalInstance while we are loading
            globalInstance = this;

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                Application.ThreadException += HandleThreadException;
            }

            client = client0;

            // Initialize current time zone, and mark when we started
            GetWorldTimeZone();
            StartupTimeUTC = DateTime.UtcNow;

            // Are we running mono?
            monoRuntime = Type.GetType("Mono.Runtime") != null;

            netcom = new RadegastNetcom(this);
            state = new StateManager(this);
            mediaManager = new MediaManager(this);
            commandsManager = new CommandsManager(this);
            ContextActionManager = new ContextActionsManager(this);
            movement = new RadegastMovement(this);

            InitializeLoggingAndConfig();
            InitializeClient(client);

            rlv = new RLVManager(this);
            gridManager = new GridManager(this);
            gridManager.LoadGrids();

            names = new NameManager(this);

            mainForm = new frmMain(this);
            mainForm.InitializeControls();

            mainForm.Load += new EventHandler(mainForm_Load);
            pluginManager = new PluginManager(this);
            pluginManager.ScanAndLoadPlugins();
        }
        public override CmdResult ExecuteRequest(CmdRequest args0)
        {
            var args = args0.GetProperty("position");
            if (args == null || args.Length == 0) args = new[] { "show" };
            if (PanelGUI == null)
            {
                if (Client.TheRadegastInstance == null)
                {
                    CogbotGUI.EnsureBotClientHasRadegast(Client);
                    int max = 40;
                    while (Client.TheRadegastInstance == null && max > 0)
                    {
                        max--;
                        Thread.Sleep(1000);
                    }
                    if (Client.TheRadegastInstance == null)
                    {
                        return Failure("Could not make client in timely manner");
                    }
                }
                PanelGUI = Client.TheRadegastInstance.MainForm;
                // (new Thread(() =>
                {
                    PanelGUI.Closing += new CancelEventHandler(delegate(object sender, CancelEventArgs e)
                    {
                        PanelGUI = null;
                    });
                    //Application.EnableVisualStyles();
                    ////PanelGUI.Invoke(new MethodInvoker(PanelGUI.Show));
                    //PanelGUI.BeginInvoke(new MethodInvoker(() =>
                    //                                           {
                    //                                               (new Thread(() => {
                    //                                               Application.Run(PanelGUI);
                    //                                               })).Start();
                    //                                           }));
                    //Application.Run(PanelGUI);
                }
                // )).Start();
            }
            string arg0 = args[0].ToLower();

            Control.CheckForIllegalCrossThreadCalls = false;

            switch (arg0)
            {
                case "show":
                    {
                        //(new Thread(() => {
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            PanelGUI.Visible = true;
                            PanelGUI.Show();
                        }));
                        //PanelGUI.Show();
                        //})).Start();
                        return Success("radegast shown");
                    }
                case "hide":
                    {
                        if (!PanelGUI.IsHandleCreated) return Success("No handle to " + arg0);
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            PanelGUI.Visible = false;
                        }));
                        return Success("radegast " + arg0);
                    }
                case "maximize":
                case "maximized":
                    {
                        if (!PanelGUI.IsHandleCreated) return Success("No handle to " + arg0);
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            PanelGUI.WindowState = FormWindowState.Maximized;
                            PanelGUI.Visible = true;
                        }));
                        return Success("radegast " + arg0);
                    }
                case "tray":
                    {                        
                        if (!PanelGUI.IsHandleCreated) return Success("No handle to " + arg0);
                        TheBotClient.TheRadegastInstance.GlobalSettings["minimize_to_tray"] = new OSDBoolean(true);
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            PanelGUI.WindowState = FormWindowState.Minimized;
                        }));
                        return Success("radegast " + arg0);
                    }
                case "minimize":
                case "minimized":
                    {
                        if (!PanelGUI.IsHandleCreated) return Success("No handle to " + arg0);
                        TheBotClient.TheRadegastInstance.GlobalSettings["minimize_to_tray"] = new OSDBoolean(false);
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            PanelGUI.WindowState = FormWindowState.Minimized;
                        }));
                        return Success("radegast " + arg0);
                    }
                case "normal":
                    {
                        if (!PanelGUI.IsHandleCreated) return Success("No handle to " + arg0);
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            PanelGUI.WindowState = FormWindowState.Normal;
                            PanelGUI.Visible = true;
                        }));
                        return Success("radegast " + arg0);
                    }
                default:
                    return Success("Unknow state");
            }
        }