static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm mainForm = new MainForm(); DataDatabase.InitializeDatabase(mainForm, mainForm.SyncIntervalBox); SyncInfoGiver.Initialization(mainForm); Synchronization.RunAutoSync(); Synchronization.SyncNow(); Application.Run(mainForm); DataDatabase.SaveChanges(); }
/// <summary> /// thread save synchronisation /// </summary> private static void Sync() { lock (SyncInfoGiver.SyncInfoGiverLocker) SyncInfoGiver.SyncInfo = "Synchronisation has started"; lock (SyncInfoGiver.SyncInfoGiverLocker) SyncInfoGiver.IsProccessingSync = true; try { lock (DataDatabase.userDatabase) { foreach (var user in DataDatabase.userDatabase) { DateTime start = DateTime.Now - TimeSpan.FromDays(user.PastSyncInterval); DateTime end; if (user.IsFutureSpecified) { end = DateTime.Now + TimeSpan.FromDays(user.FutureSyncInterval.Value); } else { end = DateTime.MaxValue; } SyncTC(user, start, end); SyncGoogle(user, start, end); } DataDatabase.SaveChanges(); lock (SyncInfoGiver.SyncInfoGiverLocker) SyncInfoGiver.WasLastSyncSuccessful = true; } } catch (Exception ex) { lock (SyncInfoGiver.SyncInfoGiverLocker) SyncInfoGiver.ErrorMessage = ex.Message; } finally { lock (SyncInfoGiver.SyncInfoGiverLocker) SyncInfoGiver.IsProccessingSync = false; } }