Example #1
0
        private void OnExiting()
        {
            Exiting?.Invoke(this, EventArgs.Empty);

            _icon.Hide();
            Application.Exit();
        }
Example #2
0
        /// <returns>true to cancel</returns>
        protected virtual bool OnExitRequested()
        {
            if (exitInitiated)
            {
                return(false);
            }

            bool?response = null;

            UpdateThread.Scheduler.Add(delegate { response = Exiting?.Invoke() == true; });

            //wait for a potentially blocking response
            while (!response.HasValue)
            {
                Thread.Sleep(1);
            }

            if (response ?? false)
            {
                return(true);
            }

            Exit();
            return(false);
        }
Example #3
0
        private void ThreadAction()
        {
            // Set to highest priority
            // Thread.CurrentThread.Priority = ThreadPriority.Highest;

            //
            while (_isAlive)
            {
                lock (_queue)
                {
                    // Wait for jobs (and still alive)
                    while (_queue.Count == 0 && _isAlive)
                    {
                        Monitor.Wait(_queue);
                    }

                    // Process all jobs
                    while (_queue.Count > 0)
                    {
                        var action = _queue.Dequeue();

                        lock (action)
                        {
                            action(); //
                            Monitor.PulseAll(action);
                        }
                    }
                }
            }

            Exiting?.Invoke();
        }
 /// <summary>
 /// Fires the paragon.app.runtime.onExiting event to JavaScript.
 /// </summary>
 private void RaiseExiting()
 {
     Exiting.Raise(this, new ApplicationExitingEventArgs(_sessionEnding));
     // Give a bit of time for the event to fire in JavaScript.
     Thread.Sleep(200);
     CloseEventPage(true);
 }
Example #5
0
        static void Main(string[] args)
        {
            Daemon daemon;
            bool   standalone;

            if (args.Length == 0)
            {
                args = new string[] { "/?" };
            }

            standalone = false;
            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "/s")
                {
                    standalone = true;
                }
                else if (args[i] == "/?")
                {
                    Console.WriteLine("Usage: TedMonitor /h=<hostname> [/i=<refresh-interval>] [/o=<out-dir>]");
                    Console.WriteLine("                  [/f=<fade-start-%>] [/s=<max_solar_kw>]");
                    Console.WriteLine();
                    Console.WriteLine("/h=<hostname>     The hostname or IP address of your TED ECC");
                    Console.WriteLine("/i=<refresh-int>  The interval, in seconds, to wait between refreshing TED data");
                    Console.WriteLine("                  and updating output files");
                    Console.WriteLine("/o=<out-dir>      The directory the output files are written to");
                    Console.WriteLine("/f=<fade-start>   If specified, the percentage at which spyder list should");
                    Console.WriteLine("                  fade to black. If not specified, no fade is applied.");
                    Console.WriteLine("/s=<max_solar_w>  The maximum output, in watts, of the solar/generation system,");
                    Console.WriteLine("                  if a Generation MTU is exists in the system. Required to ");
                    Console.WriteLine("                  generate the 'solar-now' output");
                    Console.WriteLine("/d                Enable debug output");
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.WriteLine("Generated output files:");
                    for (int x = 0; x < MonitorThread.supported_macros.Length; x++)
                    {
                        Console.WriteLine("{0}.ted:", MonitorThread.supported_macros[x]);
                        Console.WriteLine(MonitorThread.macro_descriptions[x]);
                        Console.WriteLine();
                    }
                    return;
                }
            }

            if (!standalone)
            {
                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    Console.WriteLine("Must be run as Windows Service or with '/s' argument (to run standalone.)");
                    return;
                }
            }
            daemon = new Daemon();
            daemon.OnStart(args);
            Exiting.Wait();
        }
Example #6
0
 /// <summary>
 /// Calls the <see cref="onExiting"/> and <see cref="Exiting"/> events, if they are valid.
 /// Prefer <see cref="Exiting"/> if you are programmatically adding event handlers at
 /// runtime. If you are adding event handlers in the Unity Editor, prefer <see
 /// cref="onExiting"/>. If you are waiting for this event in a subclass of StateController,
 /// prefer overriding the <see cref="OnExiting"/> method.
 /// </summary>
 protected virtual void OnExiting()
 {
     if (!skipEvents)
     {
         if (onExiting != null)
         {
             onExiting.Invoke();
         }
         Exiting?.Invoke(this, EventArgs.Empty);
     }
 }
        private static void OnExiting(PluginApplicationContext context)
        {
            if (context == null)
            {
                return;
            }

            Exiting?.Invoke(context, EventArgs.Empty);

            //激发当前上下文的“Exiting”事件
            context.RaiseExiting();
        }
Example #8
0
        internal virtual void OnExiting(IRpcSession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if (!Collection.Contains(session))
            {
                return;
            }

            Exiting?.Invoke(this, new EventArgs <IRpcSession>(session));

            Collection.Remove(session);
        }
Example #9
0
        /// <summary>
        /// Overloaded. Immediately releases the unmanaged resources used by this object.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (!initialized)
            {
                return;
            }

            Log.Message("");
            Log.Message("-------- Game Shutting Down --------");

            //	wait for server
            //	if it is still running :
            cl.Wait();
            sv.Wait();

            //	call exit event :
            Exiting?.Invoke(this, EventArgs.Empty);

            if (disposing)
            {
                while (modules.Any())
                {
                    var module = modules.Pop();
                    Log.Message("Disposing : {0}", module.GetType().Name);
                    module.Dispose();
                }

                Log.Message("Disposing : Content");
                SafeDispose(ref content);

                Log.Message("Disposing : InputDevice");
                SafeDispose(ref inputDevice);

                Log.Message("Disposing : GraphicsDevice");
                SafeDispose(ref graphicsDevice);

                Log.Message("Disposing : UserStorage");
                SafeDispose(ref userStorage);
            }

            base.Dispose(disposing);

            Log.Message("------------------------------------------");
            Log.Message("");

            ReportActiveComObjects();
        }
Example #10
0
        public static void Exit(ExitCodes reason)
        {
            if (Exiting != null)
            {
                EventHandler <EventArgs>[] delegates = (EventHandler <EventArgs>[])Exiting.GetInvocationList();
                if (delegates != null)
                {
                    EventArgs e = new EventArgs();
                    for (int i = 0; i < delegates.Length; i++)
                    {
                        try
                        {
                            delegates[i].Invoke(null, e);
                        }
                        catch
                        {
                        }
                    }
                }
            }

            Environment.Exit((int)reason);
        }
Example #11
0
        /// <summary>
        /// Shuts down the engine, cleaning up resources.
        /// </summary>
        public static void Shutdown(int exitCode = 1)
        {
            if (IsExiting)
            {
                return;
            }

            Logger.Warn("Shutting down...");

            AnalyticsService.EndSession();

            ContentProvider.DeleteDirectory(TempPath);

            IsExiting = true;

            var dataModel = Game.DataModel;

            try
            {
                dataModel.OnClose();
            }
            catch (Exception)
            {
                Logger.Error("DataModel OnClose callback errored.");
            }

            Settings.Save();
            UserSettings.Save();

            Exiting?.Invoke(null, null);

            CancelTokenSource.Cancel();

            Logger.Info("dEngine has been shutdown.");

            Environment.Exit(0);
        }
Example #12
0
 /// <inheritdoc />
 protected sealed override void InitializeEvents() => LibuiLibrary.uiOnShouldQuit(data =>
 {
     CancelEventArgs args = new CancelEventArgs();
     Exiting?.Invoke(this, args);
     return(!args.Cancel);
 }, IntPtr.Zero);
Example #13
0
 /// <summary>
 /// Raises an Exiting event. Override this method to add code to handle when the game is exiting.
 /// </summary>
 /// <param name="sender">The Game.</param>
 /// <param name="args">Arguments for the Exiting event.</param>
 protected virtual void OnExiting(object sender, EventArgs args)
 {
     Exiting?.Invoke(this, args);
 }
Example #14
0
 protected virtual void OnExiting()
 {
     Exiting?.Invoke(this, EventArgs.Empty);
 }
Example #15
0
 public virtual void Exit()
 {
     Exiting?.Invoke(this, EventArgs.Empty);
 }
 public override Task ExitAsync(ChromiumProcess p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);
Example #17
0
 public static bool DoExiting() => Exiting?.Invoke() ?? true;
Example #18
0
 private void btnExit_Click(object sender, RoutedEventArgs e)
 {
     Exiting?.Invoke(sender, e);
 }
Example #19
0
 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);
Example #20
0
 private static void Exit(ExitCodes code = ExitCodes.Normal)
 {
     Exiting?.Invoke();
     Environment.Exit((int)code);
 }
Example #21
0
 protected void OnExiting(object sender, EventArgs args)
 {
     Exiting?.Invoke(this, EventArgs.Empty);
 }
Example #22
0
 public override Task ExitAsync(FirefoxProcessManager p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);
Example #23
0
        public Game()
        {
            OpenTK.Graphics.GraphicsContext.ShareContexts = true;
            var window = new GameWindow(1280, 720);

            Window = new Window(window);
            ConstructContext();

            GraphicsDevice          = new GraphicsDevice(this, Context);
            GraphicsDevice.Viewport = new Viewport(window.ClientRectangle);
            window.Context.MakeCurrent(window.WindowInfo);
            window.Context.LoadAll();
            GL.Viewport(window.ClientRectangle);
            //Window.Location = new System.Drawing.Point();
            Mouse = new MouseDevice(window.Mouse);
            engenious.Input.Mouse.UpdateWindow(window);
            window.FocusedChanged += Window_FocusedChanged;
            window.Closing        += delegate(object sender, System.ComponentModel.CancelEventArgs e)
            {
                Exiting?.Invoke(this, new EventArgs());
            };

            gameTime = new GameTime(new TimeSpan(), new TimeSpan());

            window.UpdateFrame += delegate(object sender, FrameEventArgs e)
            {
                Components.Sort();

                gameTime.Update(e.Time);

                Update(gameTime);
            };
            window.RenderFrame += delegate(object sender, FrameEventArgs e)
            {
                ThreadingHelper.RunUIThread();
                GraphicsDevice.Clear(Color.CornflowerBlue);
                Draw(gameTime);

                GraphicsDevice.Present();
            };
            window.Resize += delegate(object sender, EventArgs e)
            {
                GraphicsDevice.Viewport = new Viewport(window.ClientRectangle);
                GL.Viewport(window.ClientRectangle);

                Resized?.Invoke(sender, e);
                OnResize(this, e);
            };
            window.Load += delegate(object sender, EventArgs e)
            {
                Initialize();
                LoadContent();
            };
            window.Closing += delegate(object sender, System.ComponentModel.CancelEventArgs e)
            {
                OnExiting(this, new EventArgs());
            };
            window.KeyPress += delegate(object sender, KeyPressEventArgs e)
            {
                KeyPress?.Invoke(this, e.KeyChar);
            };

            //Window.Context.MakeCurrent(Window.WindowInfo);

            Content    = new engenious.Content.ContentManager(GraphicsDevice);
            Components = new GameComponentCollection();
        }
Example #24
0
 protected override void OnExiting(object sender, EventArgs args)
 {
     Exiting?.Invoke(this, new EventArgs());
     base.OnExiting(sender, args);
     Process.GetCurrentProcess().Kill();
 }
Example #25
0
 protected void OnExiting(object source, EventArgs e)
 {
     Exiting?.Invoke(this, e);
 }
 private void ApplicationOnExiting(object sender, ApplicationExitingEventArgs e)
 {
     Exiting.Raise(() => new object[] { e.SessionEnding });
 }
Example #27
0
 protected virtual void OnExiting(CancelEventArgs e)
 {
     Exiting?.Invoke(this, e);
 }
Example #28
0
    ///// Event wrappers /////

    protected virtual void RaiseExiting() => Exiting?.Invoke(this, EventArgs.Empty);