Пример #1
0
 public static void Start()
 {
     lock (_lock)
     {
         if (_fileBackup == null)
         {
             _fileBackup = FileBackupManager.Instance;
             Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
         }
     }
 }
Пример #2
0
        public static void Stop()
        {
            lock (_lock)
            {
                if (_fileBackup != null)
                {
                    try
                    {
                        _fileBackup.Dispose();
                    }
                    catch { }

                    _fileBackup = null;
                }
            }
        }
Пример #3
0
        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // STOP
                    foreach (FileSystemWatcher fsw in _fileSystemWatcherMap.Values)
                    {
                        //fsw.EnableRaisingEvents = false;
                        fsw.Dispose();
                    }
                    _fileSystemWatcherMap.Clear();

                    // wait on pending jobs... for a maximum of 10 seconds
                    DateTime startTime = DateTime.Now;
                    TimeSpan timeout   = new TimeSpan(0, 0, 10);
                    while (FileBackupJob.PendingJobs && (DateTime.Now - startTime) < timeout)
                    {
                        try
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        catch { }
                    }

                    //if (backupIdentity != null)
                    //{
                    //    backupIdentity.Dispose();
                    //    backupIdentity = null;
                    //}

                    if (_windowsImpersonationContext != null)
                    {
                        Impersonater.LogOff(_windowsImpersonationContext);
                        _windowsImpersonationContext.Dispose();
                        _windowsImpersonationContext = null;
                    }
                }

                FileBackupManager._singleton = null;
                _disposed = true;
            }
        }