Example #1
0
        private void MainFormLoad()
        {
            try
            {
                this.OnCreateMainForm();

                while (!(this._bSplashScreenClosed))
                {
                    Application.DoEvents();
                }

                DisposeDelegate SplashScreenFormDisposeDelegate = new DisposeDelegate(this._SplashScreenForm.Dispose);

                this._SplashScreenForm.Invoke(SplashScreenFormDisposeDelegate);

                this._SplashScreenForm = null;

                //必须先显示,再激活,否则主窗体不能在启动窗体消失后出现
                this._PrimaryForm.Show();
                this._PrimaryForm.Activate();

                this._PrimaryForm.Closed += new EventHandler(_PrimaryForm_Closed);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message + "MainFormLoad");
            }
        }
Example #2
0
        public JSObject(object target)
        {
            var type          = target.GetType();
            var invokeMethod  = type.GetMethod(nameof(Invoke));
            var disposeMethod = type.GetMethod(nameof(Dispose));

            _invokeMethodDelegate  = Delegate.CreateDelegate(typeof(InvokeDelegate), target, invokeMethod) as InvokeDelegate;
            _disposeMethodDelegate = Delegate.CreateDelegate(typeof(DisposeDelegate), target, disposeMethod) as DisposeDelegate;
        }
Example #3
0
        /// <summary>
        /// Implementation method for DisposableBase.  Called by Disposable base either for explicit dispose or as part of the finalizer pattern.
        /// </summary>
        /// <param name="disposeType">Gives the dispose type.  DisposeType.CalledExplicitly will trigger the contained delegate to be invoked.  DisposeType.CalledByFinalizer will not.</param>
        protected override void Dispose(DisposableBase.DisposeType disposeType)
        {
            if (disposeType == DisposeType.CalledExplicitly && disposeDelegate != null)
            {
                disposeDelegate();

                disposeDelegate = null;
            }
        }
        public ConnectionPool(int size, Func <sqlite3> generator, DisposeDelegate disposer)
        {
            for (int i = 0; i < size; i++)
            {
                _pool.Add(generator());
            }

            _disposer = disposer;
        }
Example #5
0
        public JSObject(object target)
        {
            Type type = target.GetType();

            MethodInfo invokeMethod = type.GetMethod(nameof(Invoke)) ??
                                      throw new NullReferenceException($"{nameof(JSObject)}.{nameof(invokeMethod)}: failed to initialize");

            MethodInfo disposeMethod = type.GetMethod(nameof(Dispose)) ??
                                       throw new NullReferenceException($"{nameof(JSObject)}.{nameof(disposeMethod)}: failed to initialize");;

            _invokeMethodDelegate = Delegate.CreateDelegate(typeof(InvokeDelegate), target, invokeMethod) as InvokeDelegate ??
                                    throw new NullReferenceException($"{nameof(JSObject)}.{nameof(_invokeMethodDelegate)}: failed to initialize");

            _disposeMethodDelegate = Delegate.CreateDelegate(typeof(DisposeDelegate), target, disposeMethod) as DisposeDelegate ??
                                     throw new NullReferenceException($"{nameof(JSObject)}.{nameof(_invokeMethodDelegate)}: failed to initialize");
        }
Example #6
0
        public static int DisposeApi()
        {
            if (m_hDllHandle == IntPtr.Zero)
            {
                return(0);
            }

            IntPtr          pFunc = GetProcAddress(m_hDllHandle, "Dispose");
            DisposeDelegate d     = (DisposeDelegate)Marshal.GetDelegateForFunctionPointer(pFunc, typeof(DisposeDelegate));

            d();

            m_hDllHandle = IntPtr.Zero;
            m_strDllFile = "";

            return(1);
        }
        private static Func <IDisposable> ReusableDisposableLock(
            Action acquire, Action release)
        {
            var disposable = new DisposeDelegate(release);

            return(() =>
            {
                //prevent ThreadAbortException from occurring during lock acquisition
                try { }
                finally
                {
                    acquire();
                    //implement the same change introduced to c# 4.0 to capture if the lock was taken (without an exception)
                    //if the next line executes, then the lock should be released when we call disposable.Dispose()
                    disposable.LockWasTaken = true;
                }
                return disposable;
            });
        }
Example #8
0
    private void MainFormLoad()
    {
        this.OnCreateMainForm();

        while (!(this._bSplashScreenClosed))
        {
            Application.DoEvents();
        }
        DisposeDelegate SplashScreenFormDisposeDelegate = new DisposeDelegate(this._SplashScreenForm.Dispose);

        this._SplashScreenForm.Invoke(SplashScreenFormDisposeDelegate);
        this._SplashScreenForm = null;
        //必须先显示,再激活,否则主窗体不能在启动窗体消失后出现
        this._PrimaryForm.Show();
        this._PrimaryForm.TopMost = true;
        this._PrimaryForm.TopMost = false;
        //this._PrimaryForm.BringToFront();
        this._PrimaryForm.Closed += new EventHandler(_PrimaryForm_Closed);
    }
Example #9
0
        private void MainFormLoad()
        {

            this.OnCreateMainForm();



            while (!(this._bSplashScreenClosed))
            {

                Application.DoEvents();

            }

        
        DisposeDelegate SplashScreenFormDisposeDelegate = new DisposeDelegate(this._SplashScreenForm.Dispose ); 

        this._SplashScreenForm.Invoke(SplashScreenFormDisposeDelegate); 

        this._SplashScreenForm = null;

        //必须先显示,再激活,否则主窗体不能在启动窗体消失后出现 

        this._PrimaryForm.Show();

        this._PrimaryForm.Activate();



        this._PrimaryForm.Closed += new EventHandler(_PrimaryForm_Closed); 
        }
Example #10
0
        /// <summary>
        /// Disposeを別スレッドからコールする。
        /// </summary>
        public void InvokeDispose()
        {
            var dispose = new DisposeDelegate(Dispose);

            this.Invoke(dispose);
        }
Example #11
0
        /// <summary>
        /// Dispose of the chess game and the chess form.
        /// </summary>
        public void Dispose()
        {
            DisposeDelegate dd = new DisposeDelegate(_ChessInterface.Kill);
            try
            {
                _ChessInterface.Invoke(dd, new object[0]);
            }
            catch
            {
                // TODO: find out exactly which exception is thrown here
                // Throws an exception. We can't seem to fix this, but it works, so we just
                // swallow the exception, and do nothing (Indian-C#-programming-style)
            }

            this.Dispose();
        }
Example #12
0
 /// <summary>
 /// Constructor:  Caller provides the delegate to be invoked on explicit dispose of this object.
 /// </summary>
 public InvokeDelegateOnDispose(DisposeDelegate disposeDelegate)
 {
     this.disposeDelegate = disposeDelegate;
 }
Example #13
0
 public ObjDict(DisposeDelegate dispose)
 {
     DisposeCallback = dispose;
 }