What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

[TICKET] Config window not closing FIX!!!!!

sinterlkaas

New Member
Joined
Jan 17, 2012
Messages
536
Reaction score
14
This seems to fix the bug that caused DB not to close fully when using the config window for plugins:
more info can be found here:
c# - How to exit a WPF app programmatically? - Stack Overflow

this is a example plugin to proof it: when you disable the plugin and open the config window then close it + close DB it does not shutdown fully
after enabling it and try the same again it does close

used the invoke method because the App.current.shutdown needs to be called by thread owner ...

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Threading;
using System.Diagnostics;

using Zeta;
using Zeta.Common;
using Zeta.CommonBot;
using Zeta.Common.Plugins;
using Demonbuddy;

namespace MyPlugin
{
    partial class MyPlugin : IPlugin
    {
        #region IPLUGIN
        public string Author { get { return "sinterlkaas"; } }
        public string Description { get { return ""; } }
        public string Name { get { return "v" + Version.ToString(); } }
        public Version Version { get { return new Version(0, 1); } }

        public Window DisplayWindow { get {
            Window w = new Window();
            
            return w; 
        } }
        public void Log(string message, LogLevel level = LogLevel.Normal)
        {
            Logging.Write(level, string.Format("[{0}] {1}", Name, message));
        }

        public void OnInitialize()
        {
            Log("Initialized");
        }
        public void OnShutdown()
        {
        }

        public void OnEnabled()
        {
            Log("Enabled");
            thCloseCheck = new Thread(new ThreadStart(worker));
            //thCloseCheck.IsBackground = true;
            thCloseCheck.Start();
        }
        public void OnDisabled()
        {
            Log("Disabled");
            thCloseCheck.Abort();
        }
        public bool Equals(IPlugin other)
        {
            return (other.Name == Name) && (other.Version == Version);
        }

        public void OnPulse()
        {
        }
        #endregion


        Thread thCloseCheck;
        void worker()
        {
            while (true)
            {
                if (isClosing)
                {
                    App.Current.Dispatcher.Invoke(
                        new Action(
                            delegate()
                            {
                                App.Current.Shutdown();
                            }
                        ));

                    break;
                }
                Thread.Sleep(100);
            }

        }

        bool isClosing
        {
            get
            {
                IntPtr h = Process.GetCurrentProcess().MainWindowHandle;
                return (h == IntPtr.Zero || h == null);
            }
        }
    }
}
 
Back
Top