当前位置: 首页>>代码示例>>C#>>正文


C# IJob.Execute方法代码示例

本文整理汇总了C#中IJob.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# IJob.Execute方法的具体用法?C# IJob.Execute怎么用?C# IJob.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IJob的用法示例。


在下文中一共展示了IJob.Execute方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetWork

        public Task GetWork(IJob job)
        {
            Task task;
            try
            {
                task = job.Execute();
            }
            catch (Exception e)
            {
                QuietLog.LogHandledException(e);
                return new Task(() => {}); // returning dummy task so the job scheduler doesn't see errors
            }

            // wrapping the task inside an outer task which will continue with an error handler.
            return CreateWrappingContinuingTask(task, t =>
            {
                if (t.IsCanceled)
                {
                    Debug.WriteLine("Background Task Canceled: " + job.GetType());
                }
                else if (t.IsFaulted)
                {
                    Debug.WriteLine("Background Task Faulted: " + job.GetType());
                    QuietLog.LogHandledException(task.Exception);
                }
                // else happiness
            }, TaskContinuationOptions.ExecuteSynchronously);
        }
开发者ID:henrycomein,项目名称:NuGetGallery,代码行数:28,代码来源:NuGetJobCoordinator.cs

示例2: Execute

        public async Task Execute(IJob job)
        {
            var source = new CancellationTokenSource(_timeout);
            var cancellation = new CancellationToken();
            var task = Task.Factory.StartNew(() => job.Execute(source.Token), source.Token);
            var timeout = Task.Delay(_timeout, cancellation);
            if (await Task.WhenAny(task, timeout) == task)
            {
                await task;
            }
            else
            {
                var marker = new TaskCompletionSource<object>();
                marker.SetException(new TimeoutException("Timed out after " + _timeout));

                await marker.Task;
            }
        }
开发者ID:joemcbride,项目名称:fubumvc,代码行数:18,代码来源:IJob.cs

示例3: GetWork

        // Returns a task with the work to do if work is available to do and another web server
        // in the web farm isn't already doing it.
        public Task GetWork(IJob job)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            var unitOfWork = ReserveWork(WebServerWorkerId, job);
            if (unitOfWork == null)
            {
                return null;
            }

            Task task = null;
            try
            {
                task = job.Execute();
            }
            catch (Exception e)
            {
                task = new Task(() => { throw e; });
            }
            task.ContinueWith(c =>
            {
                if (c.IsFaulted)
                {
                    unitOfWork.Fail(c.Exception.GetBaseException());
                }
                else
                {
                    unitOfWork.Complete();
                }
            });

            return task;
        }
开发者ID:regisbsb,项目名称:WebBackgrounder,代码行数:38,代码来源:WebFarmJobCoordinator.cs

示例4: RunJobCore

        private void RunJobCore(IJobContext context, Operation operation, IJob job)
        {
            try
            {
                job.Execute(context, operation);

                Logger.Instance.LogFormat(LogType.Trace, this, Resources.JobExecuteFinished, job.GetType().Name);
            }
            catch (Exception ex)
            {
                string message = (job.IsAsync) ? Properties.Resources.JobExecuteAsyncFailed : Properties.Resources.JobExecuteSyncFailed;

                Logger.Instance.LogFormat(LogType.Warning, this, string.Format(message, job.GetType().Name));
                Logger.Instance.LogException(this, ex);
            }
        }
开发者ID:huoxudong125,项目名称:AlarmWorkflow,代码行数:16,代码来源:JobManager.cs

示例5: Execute

 /// <summary>
 ///     Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.ITrigger" />
 ///     fires that is associated with the <see cref="T:Quartz.IJob" />.
 /// </summary>
 /// <remarks>
 ///     The implementation may wish to set a  result object on the
 ///     JobExecutionContext before this method exits.  The result itself
 ///     is meaningless to Quartz, but may be informative to
 ///     <see cref="T:Quartz.IJobListener" />s or
 ///     <see cref="T:Quartz.ITriggerListener" />s that are watching the job's
 ///     execution.
 /// </remarks>
 /// <param name="context">The execution context.</param>
 /// <exception cref="SchedulerConfigException">Job cannot be instantiated.</exception>
 public void Execute(IJobExecutionContext context)
 {
     var childContainer = unityContainer.CreateChildContainer();
     try
     {
         RunningJob = (IJob)childContainer.Resolve(bundle.JobDetail.JobType);
         RunningJob.Execute(context);
     }
     catch (JobExecutionException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new JobExecutionException(string.Format(CultureInfo.InvariantCulture,
             "Failed to execute Job '{0}' of type '{1}'",
             bundle.JobDetail.Key, bundle.JobDetail.JobType), ex);
     }
     finally
     {
         RunningJob = null;
         childContainer.Dispose();
     }
 }
开发者ID:wezmag,项目名称:Quartz.Unity,代码行数:38,代码来源:UnityJobFactory.cs

示例6: CreateJobAction

        /// <summary>
        /// Action creation helper.
        /// Given a job, job parameters and a job execution, 
        /// will wrap the execution of the job into a <see cref="System.Action"/>.
        /// </summary>
        /// <param name="job">the job to execute</param>
        /// <param name="jobParameters">the job parameters</param>
        /// <param name="jobExecution">the job execution</param>
        /// <returns></returns>
        private static Action CreateJobAction(IJob job, JobParameters jobParameters, JobExecution jobExecution)
        {
            Action jobAction = (() =>
            {
                try
                {
                    Logger.Info("Job: [{0} ] launched with the following parameters:[{1}]",job,jobParameters);
                    job.Execute(jobExecution);
                    Logger.Info("Job: [{0}] completed with the following parameters:[{1}] and the following status: [{2}]",
                                 job,jobParameters,jobExecution.Status);

                }
                catch (Exception exception)
                {
                    Logger.Info("Job: [{0}] failed unexpectedly and fatally with the following parameters: [{1}]",job,exception);
                     throw;
                }
            });
            return jobAction;
        }
开发者ID:SummerBatch,项目名称:SummerBatch,代码行数:29,代码来源:SimpleJobLauncher.cs

示例7: GetWork

 public Task GetWork(IJob job)
 {
     return job.Execute();
 }
开发者ID:regisbsb,项目名称:WebBackgrounder,代码行数:4,代码来源:SingleServerJobCoordinator.cs

示例8: RunJob

 private void RunJob(IJob job)
 {
     try
     {
         DateTime start = DateTime.Now;
         var newJobs = job.Execute();
         DateTime end = DateTime.Now;
         logger.Info("{0} finished in {2} s. and returned {1} new jobs.", job.Name, newJobs.Count, (end-start).TotalSeconds);
         foreach (var newJob in newJobs)
         {
             AddJob(newJob);
         }
     }
     catch (Exception exp2)
     {
         logger.Error(exp2, "{0} failed while executing.", job.Name);
     }
 }
开发者ID:KRSogaard,项目名称:JobScrapingFramework,代码行数:18,代码来源:JobEngine.cs

示例9: RunJobCore

        private void RunJobCore(IJobContext context, Operation operation, IJob job)
        {
            // Run the job. If the job fails, ignore that exception as well but log it too!
            try
            {
                job.Execute(context, operation);
            }
            catch (Exception ex)
            {
                string message = (job.IsAsync) ? Properties.Resources.JobExecuteAsyncFailed : Properties.Resources.JobExecuteSyncFailed;

                // Be careful when processing the jobs, we don't want a malicious job to terminate the process!
                Logger.Instance.LogFormat(LogType.Warning, this, string.Format(message, job.GetType().Name));
                Logger.Instance.LogException(this, ex);
            }
        }
开发者ID:Knatter33,项目名称:AlarmWorkflow,代码行数:16,代码来源:JobManager.cs

示例10: UpdateUI

 private void UpdateUI(IJob job)
 {
     job.Execute(this);
 }
开发者ID:ionhristiniuc,项目名称:chatapp,代码行数:4,代码来源:ClientForm.cs

示例11: Execute

            /// <summary>
            ///     Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.ITrigger" />
            ///     fires that is associated with the <see cref="T:Quartz.IJob" />.
            /// </summary>
            /// <remarks>
            ///     The implementation may wish to set a  result object on the
            ///     JobExecutionContext before this method exits.  The result itself
            ///     is meaningless to Quartz, but may be informative to
            ///     <see cref="T:Quartz.IJobListener" />s or
            ///     <see cref="T:Quartz.ITriggerListener" />s that are watching the job's
            ///     execution.
            /// </remarks>
            /// <param name="context">The execution context.</param>
            /// <exception cref="SchedulerConfigException">Job cannot be instantiated.</exception>
            public void Execute(IJobExecutionContext context)
            {
                var childContainer = _unityContainer.CreateChildContainer();

                try
                {
                    try
                    {
                        RunningJob = (IJob)childContainer.Resolve(Bundle.JobDetail.JobType);
                    }
                    catch (Exception ex)
                    {
                        throw new JobExecutionException(string.Format("Failed to instantiate Job '{0}' of type '{1}'",
                            Bundle.JobDetail.Key, Bundle.JobDetail.JobType), ex);
                    }

                    RunningJob.Execute(context);
                }
                catch (JobExecutionException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new JobExecutionException(
                        string.Format("Unhandled exception in job '{0}'. {1}", Bundle.JobDetail.Key, ex.Message), ex);
                }
                finally
                {
                    ClearJob();
                    childContainer.Dispose();
                }
            }
开发者ID:cutstock,项目名称:SampleWebService,代码行数:47,代码来源:UnityJobFactory.cs

示例12: ExecuteJob

        internal bool ExecuteJob(IJob job, out Exception ex)
        {
            bool success = false;
            ex = null;

            try
            {
                // Execute the job, with a timeout if necessary.
                int timeout = job.Timeout < 0 ? 60000 : job.Timeout;

                if (timeout > 0)
                {
                    this.logger.Info("Worker {0} ({1}) is executing job '{2}' with timeout {3}.", this.name, this.id, job.Name, job.Timeout);
                    new Action(job.Execute).InvokeWithTimeout(timeout);
                }
                else
                {
                    this.logger.Info("Worker {0} ({1}) is executing job '{2}' with no timeout.", this.name, this.id, job.Name);
                    job.Execute();
                }

                success = true;
            }
            catch (Exception tx)
            {
                ex = tx;
            }

            return success;
        }
开发者ID:ChadBurggraf,项目名称:blue-collar,代码行数:30,代码来源:Worker.cs

示例13: Execute

 /// <summary>
 ///     Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.ITrigger" />
 ///     fires that is associated with the <see cref="T:Quartz.IJob" />.
 /// </summary>
 /// <remarks>
 ///     The implementation may wish to set a  result object on the
 ///     JobExecutionContext before this method exits.  The result itself
 ///     is meaningless to Quartz, but may be informative to
 ///     <see cref="T:Quartz.IJobListener" />s or
 ///     <see cref="T:Quartz.ITriggerListener" />s that are watching the job's
 ///     execution.
 /// </remarks>
 /// <param name="context">The execution context.</param>
 /// <exception cref="SchedulerConfigException">Job cannot be instantiated.</exception>
 public void Execute(IJobExecutionContext context)
 {
     var scope = _lifetimeScope.BeginLifetimeScope(_scopeName);
     try
     {
         RunningJob = CreateJob(scope);
         RunningJob.Execute(context);
     }
     catch (Exception ex)
     {
         throw new SchedulerConfigException(string.Format(CultureInfo.InvariantCulture,
             "Failed to instantiate Job '{0}' of type '{1}'",
             _bundle.JobDetail.Key, _bundle.JobDetail.JobType), ex);
     }
     finally
     {
         RunningJob = null;
         scope.Dispose();
     }
 }
开发者ID:JustAGhosT,项目名称:Autofac.Extras.Quartz,代码行数:34,代码来源:AutofacJobFactory.cs


注:本文中的IJob.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。