/// <summary> /// Синхронизировать. /// Выполняется асинхронно. /// </summary> public static void PeriodicSync( this IServiceProvider provider, SyncThreadPriority priority, bool activateUI) { PeriodicSync(provider, priority, null, activateUI); }
/// <summary> /// Синхронизировать. /// Выполняется асинхронно. /// </summary> public static void PeriodicSync( this IServiceProvider provider, SyncThreadPriority priority, SyncRequestFinishedHandler syncFinishedHandler, bool activateUI) { DoAsyncSync( sz => sz.SyncPeriodic(activateUI), provider, syncFinishedHandler, false, priority); }
/// <summary> /// Синхронизировать форумы. /// </summary> public static void SyncForums( this IServiceProvider provider, SyncThreadPriority priority, SyncRequestFinishedHandler syncFinishedHandler, bool activateUI) { provider.SyncSpecific( JanusATInfo.ProviderName, JanusATInfo.ForumsSyncTaskName, priority, syncFinishedHandler, activateUI); }
/// <summary> /// Синхронизировать, если это возможно. /// Выполняется асинхронно. /// </summary> public static void SyncSpecific( this IServiceProvider provider, string providerName, string taskName, SyncThreadPriority priority, SyncRequestFinishedHandler syncFinishedHandler, bool activateUI) { DoAsyncSync( sz => sz.SyncSpecific(providerName, taskName, activateUI), provider, syncFinishedHandler, false, priority); }
private static Thread CreateSyncThread( ThreadStart method, SyncThreadPriority priority) { return(new Thread(method) { IsBackground = true, CurrentCulture = Thread.CurrentThread.CurrentCulture, CurrentUICulture = Thread.CurrentThread.CurrentUICulture, Priority = priority == SyncThreadPriority.Normal ? ThreadPriority.Normal : ThreadPriority.Lowest }); }
private static void DoAsyncSync( Func <ISynchronizer, IStatisticsContainer> syncProc, IServiceProvider provider, SyncRequestFinishedHandler syncFinishedHandler, bool checkAvailability, SyncThreadPriority priority) { var sz = provider.GetRequiredService <ISynchronizer>(); if (!sz.IsActive()) { var thread = CreateSyncThread( () => { try { var syncPerformed = false; IStatisticsContainer stats = null; if (!checkAvailability || sz.IsAvailable()) { syncPerformed = true; stats = syncProc(sz); } if (syncFinishedHandler != null) { provider.GetRequiredService <IUIShell>() .CreateUIAsyncOperation() .PostOperationCompleted(state => syncFinishedHandler(syncPerformed, stats), null); } } catch (Exception ex) { provider.GetRequiredService <IUIShell>() .CreateUIAsyncOperation() .PostOperationCompleted( //{{{-PossibleIntendedRethrow state => { throw ex; }, null); //{{{+PossibleIntendedRethrow } }, priority); thread.Start(); } else if (syncFinishedHandler != null) { syncFinishedHandler(false, null); } }
private static void DoAsyncSync( Func<ISynchronizer, IStatisticsContainer> syncProc, IServiceProvider provider, SyncRequestFinishedHandler syncFinishedHandler, bool checkAvailability, SyncThreadPriority priority) { var sz = provider.GetRequiredService<ISynchronizer>(); if (!sz.IsActive()) { var thread = CreateSyncThread( () => { try { var syncPerformed = false; IStatisticsContainer stats = null; if (!checkAvailability || sz.IsAvailable()) { syncPerformed = true; stats = syncProc(sz); } if (syncFinishedHandler != null) provider.GetRequiredService<IUIShell>() .CreateUIAsyncOperation() .PostOperationCompleted(state => syncFinishedHandler(syncPerformed, stats), null); } catch (Exception ex) { provider.GetRequiredService<IUIShell>() .CreateUIAsyncOperation() .PostOperationCompleted( //{{{-PossibleIntendedRethrow state => { throw ex; }, null); //{{{+PossibleIntendedRethrow } }, priority); thread.Start(); } else syncFinishedHandler?.Invoke(false, null); }
private static Thread CreateSyncThread( ThreadStart method, SyncThreadPriority priority) { return new Thread(method) { IsBackground = true, CurrentCulture = Thread.CurrentThread.CurrentCulture, CurrentUICulture = Thread.CurrentThread.CurrentUICulture, Priority = priority == SyncThreadPriority.Normal ? ThreadPriority.Normal : ThreadPriority.Lowest }; }