Beispiel #1
0
        /// <summary>
        /// Executed when there is progress reported from BackgroundWorker Logic.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void Generate_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            var worker = (BackgroundWorker)sender;

            //if (worker.CancellationPending) { } else
            if (e.UserState is Exception)
            {
                var ex = (Exception)e.UserState;

                // Delete Template Class File
                TemplateClass.Delete();

                // Log Error
                LogManager.LogError(ex);

                // Raise OnException event
                GeneratorManager.RaiseEvent <GeneratorOnExceptionEventArgs>(new GeneratorOnExceptionEventArgs(ex));
            }
            else if (e.UserState is GeneratorOnProgressEventArgs)
            {
                var eventArgs = (GeneratorOnProgressEventArgs)e.UserState;

                // Raise OnProgress event
                GeneratorManager.RaiseEvent <GeneratorOnProgressEventArgs>(eventArgs);
            }
            else if (e.UserState is GeneratorOnCompleteEventArgs)
            {
                var eventArgs = (GeneratorOnCompleteEventArgs)e.UserState;

                // Raise OnComplete event
                GeneratorManager.RaiseEvent <GeneratorOnCompleteEventArgs>(eventArgs);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Cancels the generation process.
        /// </summary>
        public static void CancelGeneration()
        {
            if (_worker != null)
            {
                _worker.CancelAsync();

                _resetEvent.WaitOne();

                _worker     = null;
                _resetEvent = null;

                // Raise OnCancel event
                GeneratorManager.RaiseEvent <GeneratorOnCancelEventArgs>(new GeneratorOnCancelEventArgs());
            }
        }