Esempio n. 1
0
        static void ExecuteBackgroundTask([NotNull] SchedulerTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            task.IsExecuting = true;
#if DEBUG_SCHEDULER
            FireEvent(TaskExecuting, task);
#endif

#if DEBUG
            task.Callback(task);
#else
            try {
                task.Callback(task);
            } catch (Exception ex) {
                Logger.LogAndReportCrash("Exception thrown by ScheduledTask callback", "fCraft", ex, false);
            } finally {
                task.IsExecuting = false;
            }
#endif

#if DEBUG_SCHEDULER
            FireEvent(TaskExecuted, task);
#endif
        }
Esempio n. 2
0
        static void ExecuteBackgroundTask(SchedulerTask task)
        {
            task.IsExecuting = true;
#if DEBUG_SCHEDULER
            task.ExecuteStart = DateTime.UtcNow;
            FireEvent(TaskExecuting, task);
#endif

#if DEBUG
            task.Callback(task);
#else
            try {
                task.Callback(task);
            } catch (Exception ex) {
                Logger.LogAndReportCrash("Exception thrown by ScheduledTask callback", "ProCraft", ex, false);
            } finally {
                task.IsExecuting = false;
            }
#endif

#if DEBUG_SCHEDULER
            task.ExecuteEnd = DateTime.UtcNow;
            FireEvent(TaskExecuted, task);
#endif
        }
Esempio n. 3
0
        private static void MainLoop() {
            while ( !Server.IsShuttingDown ) {
                DateTime ticksNow = DateTime.UtcNow;

                SchedulerTask[] taskListCache = taskCache;

                for ( int i = 0; i < taskListCache.Length && !Server.IsShuttingDown; i++ ) {
                    SchedulerTask task = taskListCache[i];
                    if ( task.IsStopped || task.NextTime > ticksNow )
                        continue;
                    if ( task.IsRecurring && task.AdjustForExecutionTime ) {
                        task.NextTime += task.Interval;
                    }

                    if ( task.IsBackground ) {
                        lock ( BackgroundTaskListLock ) {
                            BackgroundTasks.Enqueue( task );
                        }
                    } else {
                        task.IsExecuting = true;

#if DEBUG_SCHEDULER
                        FireEvent( TaskExecuting, task );
#endif

#if DEBUG
                        task.Callback( task );
                        task.IsExecuting = false;
#else
                        try {
                            task.Callback( task );
                        } catch ( Exception ex ) {
                            Logger.LogAndReportCrash( "Exception thrown by ScheduledTask callback", "fCraft", ex, false );
                        } finally {
                            task.IsExecuting = false;
                        }
#endif

#if DEBUG_SCHEDULER
                        FireEvent( TaskExecuted, task );
#endif
                    }

                    if ( !task.IsRecurring || task.MaxRepeats == 1 ) {
                        task.Stop();
                        continue;
                    }
                    task.MaxRepeats--;

                    ticksNow = DateTime.UtcNow;
                    if ( !task.AdjustForExecutionTime ) {
                        task.NextTime = ticksNow.Add( task.Interval );
                    }
                }

                Thread.Sleep( 10 );
            }
        }
Esempio n. 4
0
        static void ExecuteBackgroundTask( SchedulerTask task ) {
            task.IsExecuting = true;
#if DEBUG_SCHEDULER
                    FireEvent( TaskExecuting, task );
#endif

#if DEBUG
            task.Callback( task );
#else
                    try {
                        task.Callback( task );
                    } catch( Exception ex ) {
                        Logger.LogAndReportCrash( "Exception thrown by ScheduledTask callback", "fCraft", ex, false );
                    } finally {
                        task.IsExecuting = false;
                    }
#endif

#if DEBUG_SCHEDULER
                    FireEvent( TaskExecuted, task );
#endif
        }