public void RunJob(DistributedTask _, CancellationToken cancellationToken) { try { CancellationToken = cancellationToken; CoreContext.TenantManager.SetCurrentTenant(CurrentTenant); Thread.CurrentPrincipal = principal; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(culture); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); FolderDao = Global.DaoFactory.GetFolderDao(); FileDao = Global.DaoFactory.GetFileDao(); TagDao = Global.DaoFactory.GetTagDao(); ProviderDao = Global.DaoFactory.GetProviderDao(); FilesSecurity = new FileSecurity(Global.DaoFactory); LinkDao = Global.GetLinkDao(); Logger = Global.Logger; Total = InitTotalProgressSteps(); Do(); } catch (AuthorizingException authError) { Error = FilesCommonResource.ErrorMassage_SecurityException; Logger.Error(Error, new SecurityException(Error, authError)); } catch (AggregateException ae) { ae.Flatten().Handle(e => e is TaskCanceledException || e is OperationCanceledException); } catch (Exception error) { Error = error is TaskCanceledException || error is OperationCanceledException ? FilesCommonResource.ErrorMassage_OperationCanceledException : error.Message; Logger.Error(error, error); } finally { try { TaskInfo.SetProperty(FINISHED, true); PublishTaskInfo(); FolderDao.Dispose(); FileDao.Dispose(); TagDao.Dispose(); LinkDao.Dispose(); if (ProviderDao != null) { ProviderDao.Dispose(); } } catch { /* ignore */ } } }