Example #1
0
        /// <summary>
        /// Handles the Idle event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private static void Application_Idle(object sender, EventArgs e)
        {
            MSG message;                                    // Message to retrieve.

            // We have nothing to execute, just leave.
            if ((ApplicationIdleLoopMethod == null) || (!IsRunning))
            {
                return;
            }

            while ((HasFocus) && (!Win32API.PeekMessage(out message, IntPtr.Zero, 0, 0, PeekMessageFlags.NoRemove)))
            {
                // Reset the timer so that frame rate timing can start with the first iteration of the loop.
                if (_timingStarted)
                {
                    GorgonTiming.Reset();
                    _timingStarted = false;
                }

                GorgonTiming.Update();

                if (!ApplicationIdleLoopMethod())
                {
                    // Force an exit from the thread.
                    Application.Exit();
                    return;
                }

                // Give up CPU time if we're not focused.
                if ((ApplicationForm != null) && (!ApplicationForm.ContainsFocus) && (UnfocusedSleepTime > 0))
                {
                    Thread.Sleep(UnfocusedSleepTime);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Initializes the <see cref="Gorgon"/> class.
        /// </summary>
        static Gorgon()
        {
            PlugIns = new GorgonPlugInFactory();
            Log     = new GorgonLogFile(LogFile, "Tape_Worm");

            // Re-open the log if it's closed.
            if (Log.IsClosed)
            {
                try
                {
                    Log.Open();
                }
#if DEBUG
                catch (Exception ex)
                {
                    // Only note this in DEBUG mode.
                    GorgonDialogs.ErrorBox(ApplicationForm, ex);
                }
#else
                // ReSharper disable EmptyGeneralCatchClause
                catch
                {
                    // We don't care if logging works or not in release mode.
                }
                // ReSharper restore EmptyGeneralCatchClause
#endif
            }

            GorgonException.Log = Log;
            Log.Print("Initializing...", LoggingLevel.All);
            Log.Print("Architecture: {0}", LoggingLevel.Verbose, GorgonComputerInfo.PlatformArchitecture);
            Log.Print("Processor count: {0}", LoggingLevel.Verbose, GorgonComputerInfo.ProcessorCount);
            Log.Print("Installed Memory: {0}", LoggingLevel.Verbose, GorgonComputerInfo.TotalPhysicalRAM.FormatMemory());
            Log.Print("Available Memory: {0}", LoggingLevel.Verbose, GorgonComputerInfo.AvailablePhysicalRAM.FormatMemory());
            Log.Print("Operating System: {0} ({1})", LoggingLevel.Verbose, GorgonComputerInfo.OperatingSystemVersionText, GorgonComputerInfo.OperatingSystemArchitecture);

            // Default to using 10 milliseconds of sleep time when the application is not focused.
            UnfocusedSleepTime = 10;

            // Initializing application timing.
            GorgonTiming.Reset();
        }