Example #1
0
        /// <summary>
        /// Function to run a Gorgon application.
        /// </summary>
        /// <param name="loop">Idle loop method for the application.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="loop"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when the application is already in a <see cref="P:GorgonLibrary.Gorgon.IsRunning">running state</see>.</exception>
        public static void Run(Func <bool> loop)
        {
            if (loop == null)
            {
                throw new ArgumentNullException("loop");
            }

            if (IsRunning)
            {
                throw new InvalidOperationException(Resources.GOR_APPLICATION_ALREADY_RUNNING);
            }

            ApplicationIdleLoopMethod = loop;

            try
            {
                if (Initialize())
                {
                    return;
                }

                IsRunning      = true;
                _timingStarted = true;
                Application.Run();
            }
            catch (Exception ex)
            {
                GorgonException.LogException(ex);
                throw;
            }
            finally
            {
                CleanUp();
            }
        }
Example #2
0
        /// <summary>
        /// Function to run a Gorgon application.
        /// </summary>
        /// <param name="context">Application context to use.</param>
        /// <param name="loop">[Optional] Idle loop method for the application.</param>
        /// <remarks>This method requires an application context, but the <paramref name="loop"/> parameter is optional.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="context"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.InvalidOperationException">Thrown when the application is already in a <see cref="P:GorgonLibrary.Gorgon.IsRunning">running state</see>.</exception>
        public static void Run(ApplicationContext context, Func <bool> loop = null)
        {
            if (context == null)
            {
                throw new InvalidOperationException(Resources.GOR_NOCONTEXT);
            }

            if (IsRunning)
            {
                throw new InvalidOperationException(Resources.GOR_APPLICATION_ALREADY_RUNNING);
            }

            if (loop != null)
            {
                ApplicationIdleLoopMethod = loop;
            }

            ApplicationContext = context;

            try
            {
                if (Initialize())
                {
                    return;
                }

                IsRunning      = true;
                _timingStarted = true;
                Application.Run(context);
            }
            catch (Exception ex)
            {
                GorgonException.LogException(ex);
                throw;
            }
            finally
            {
                CleanUp();
            }
        }