void DisposeWatcher() { if (m_watcher != null && m_watcher.Watching) { m_watcher.Dispose(); } }
// The bulk of the clean-up code is implemented in Dispose(bool) protected virtual void Dispose(bool disposing) { if (_isDisposed) { return; } if (disposing) { // free managed resources // Managed resources are those that are pure .NET code and managed by the runtime and are under its direct control. DirectoryInfo = null; if (Watcher != null) { Watcher?.EndInit(); Watcher?.Dispose(); } } //// free native resources if there are any. //if (nativeResource != IntPtr.Zero) //{ // // Unmanaged resources are those that are not. File handles, pinned memory, COM objects, database connections etc // Marshal.FreeHGlobal(nativeResource); // nativeResource = IntPtr.Zero; //} _isDisposed = true; }
public void Dispose() { if (_watcher != null && _watcher.Watching) { _watcher.Dispose(); } }
private void StopWatching() { Watcher?.Dispose(); synth.SpeakAsyncCancelAll(); LastConversation = null; Watcher = null; }
protected override void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { if (_currentRecord != null) { LogJobEnd(); } _cmdSelectFolder = null; _cmdSaveList = null; _cmdCopyFiles = null; _cmdLaunchEditor = null; _currentRecord = null; if (watcher != null) { watcher.Dispose(); } if (fileHelper != null) { fileHelper.Dispose(); } } _changedFiles = null; _customFilters = null; _scanModes = null; _subFolders = null; base.Dispose(disposing); } }
private Watcher StartNewWatcher() { var newWatcher = new Watcher(); try { newWatcher.DirectoryPath = DirectoryPath; newWatcher.Filter = "*.log"; newWatcher.LineWriter = CreateWriter(); newWatcher.FileFound += WatcherFileFound; newWatcher.Start(); } catch { try { newWatcher.Dispose(); } catch { } throw; } return(newWatcher); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); // If the process has started, all three disposable objects will be valid // I would just call OnStop, but the code analysis tool doesn't look inside // it and thinks the members aren't being Disposed. if (Processors.Count > 0) { // Clean up the directory watcher and crash processor threads foreach (var Processor in Processors) { Processor.Dispose(); } Processors.Clear(); Watcher.Dispose(); Watcher = null; StatusReporter.Dispose(); StatusReporter = null; Slack.Dispose(); Slack = null; // Flush the log to disk Log.Dispose(); Log = null; } } base.Dispose(disposing); }
public Task StopAsync(CancellationToken cancellationToken) { _logger.LogInformation("Stopping Foo monitoring!"); _watcher.Dispose(); return(Task.CompletedTask); }
public void Dispose() { if (null != Watcher) { Watcher.EnableRaisingEvents = false; Watcher.Dispose(); } }
private void DestroyWatcher() { #if HRVC_DEBUG Logger.log.Critical($"Destroying FileSystemWatcher for {ContentDirectory}"); #endif Watcher.Dispose(); Watcher = null; }
public void Dispose() { if (Watcher != null) { Watchers.Remove(Watcher); Watcher.EnableRaisingEvents = false; Watcher.Dispose(); } }
protected void DisposeInternal() { if (Disposed) { return; } Watcher?.Dispose(); Disposed = true; }
public void StopWatching() { if (Watcher != null) { Watcher.EnableRaisingEvents = false; Watcher.Dispose(); Watcher = null; } }
public void Close() { if (!Completed) { return; } Watcher?.Dispose(); Client?.Exit(); }
public void Dispose_ForInvoked_DisposesWrapper( Watcher sut, [Freeze] IWrapper wrapper) { sut.Dispose(); wrapper.Received() .Dispose(); }
private void OnTimerExpired(object sender, ElapsedEventArgs e) { Watcher.EnableRaisingEvents = false; Watcher.Dispose(); _timer.Enabled = false; _timer.Dispose(); Finished?.Invoke(this, new FileMonitorFinishedArgs(this)); }
/// <summary> /// Dispose this scheduler. /// </summary> /// <param name="disposing">The boolean whether to dispose.</param> protected virtual void Dispose(bool disposing) { if (disposing) { Watcher.Changed -= OnChanged; Watcher.Created -= OnChanged; Watcher.Renamed -= OnChanged; Watcher.Dispose(); } }
public void Dispose() { Watcher.Dispose(); if (null != Reader) { Reader.Close(); Reader.Dispose(); } }
private void OnChanged(object s, FileSystemEventArgs e) { if (e.FullPath != TempPath) { return; } if (e.ChangeType != WatcherChangeTypes.Changed) { return; } try { var newFiles = File.ReadAllLines(TempPath); var filesChanged = 0; for (var i = 0; i < FileList.Length; i++) { var oldFileName = FileList[i]; var newFileName = newFiles[i]; if (oldFileName == newFileName) { continue; } File.Move(oldFileName, newFileName); filesChanged++; } Renamed?.Invoke(this, new RenamedEventArgs(filesChanged)); } catch (Exception ex) { using var dialog = new TaskDialog() { Caption = "Renamer", Icon = TaskDialogStandardIcon.Error, Text = "An error has occured while renaming files.", DetailsCollapsedLabel = "Show exception details", DetailsExpandedLabel = "Hide exception details", DetailsExpandedText = ex.ToString(), StandardButtons = TaskDialogStandardButtons.Ok }; dialog.Show(); } finally { File.Delete(TempPath); } Watcher.Dispose(); }
private void MenuRemove_Click(object sender, RoutedEventArgs e) { Watcher watcher = WatcherList.SelectedItem as Watcher; if (watcher == null) { return; } manager.Watchers.Remove(watcher); watcher.Dispose(); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (Watcher != null) { Watcher.Changed -= OnChanged; Watcher.Dispose(); Watcher = null; } } }
public override TaskStatus Run() { InfoFormat("Watching the folder {0} ...", FolderToWatch); try { if (!string.IsNullOrEmpty(SmbComputerName) && !string.IsNullOrEmpty(SmbUsername) && !string.IsNullOrEmpty(SmbPassword)) { using (NetworkShareAccesser.Access(SmbComputerName, SmbDomain, SmbUsername, SmbPassword)) { if (!Directory.Exists(FolderToWatch)) { ErrorFormat("The folder {0} does not exist.", FolderToWatch); return(new TaskStatus(Status.Error)); } InitFileSystemWatcher(); } } else { if (!Directory.Exists(FolderToWatch)) { ErrorFormat("The folder {0} does not exist.", FolderToWatch); return(new TaskStatus(Status.Error)); } InitFileSystemWatcher(); } } catch (ThreadAbortException) { if (Watcher != null) { Watcher.EnableRaisingEvents = false; Watcher.Dispose(); } throw; } catch (Exception e) { if (Watcher != null) { Watcher.EnableRaisingEvents = false; Watcher.Dispose(); } ErrorFormat("An error occured while initializing FileSystemWatcher.", e); } Info("Task finished"); return(new TaskStatus(Status.Success)); }
public void Stop() { if (watcher == null) { throw new InvalidOperationException("Watcher is not started"); } if (watcher.IsStarted) { watcher.Stop(); } watcher.Dispose(); watcher = null; }
public void Dispose() { IsDisposed = true; _isChanging = false; Watcher.Changed -= OnChanged; Watcher.Created -= OnCreated; Watcher.Deleted -= OnDeleted; Watcher.Renamed -= OnRenamed; Watcher.Dispose(); Watcher = null; }
static void Main(string[] args) { IWatcher watcher = new Watcher(); watcher.MessageHandlerEvent += ConsoleMessagePrinter.WriteMessageInConsole; ITaskManager taskManager = new TaskManager(watcher); watcher.Watch(); Console.WriteLine("Console Client working"); Console.ReadLine(); watcher.MessageHandlerEvent -= ConsoleMessagePrinter.WriteMessageInConsole; watcher.StopWatch(); watcher.Dispose(); }
public Task StopAsync(CancellationToken cancellationToken) { if (_leaderCheckTimer != null) { _leaderCheckTimer.Dispose(); } if (_watcher != null) { _watcher.Dispose(); } return(Task.CompletedTask); }
private void Init() { watcher?.Dispose(); Items.Clear(); watcher = State.Client?.ListNamespaceWithHttpMessagesAsync(watch: true) .Watch <V1Namespace, V1NamespaceList>((type, item) => { switch (type) { case WatchEventType.Added: if (!Items.Any(x => x.Metadata.Uid == item.Metadata.Uid)) { Items.Add(item); } else { Items[Items.FindIndex(x => x.Metadata.Uid == item.Metadata.Uid)] = item; } break; case WatchEventType.Modified: Items[Items.FindIndex(x => x.Metadata.Uid == item.Metadata.Uid)] = item; break; case WatchEventType.Deleted: Items.RemoveAt(Items.FindIndex(x => x.Metadata.Uid == item.Metadata.Uid)); break; case WatchEventType.Error: break; default: break; } StateHasChanged(); }); }
public void Dispose() { if (Disposed) { return; } Watcher.EnableRaisingEvents = false; Watcher.Changed -= this.WatcherOnChanged; Watcher.Deleted -= this.WatcherOnDeleted; Watcher.Renamed -= this.WatcherOnRenamed; Disposed = true; Watcher.Dispose(); Object = null; Path = null; }
static void Main(string[] args) { using (var watcher = new FileSystemWatcher(@"C:\temp") { EnableRaisingEvents = true }) { watcher.Created += new FileSystemEventHandler(watcher_Created); Console.WriteLine("Press a key to release the watcher reference."); Console.ReadKey(true); watcher = null; } Watcher.Dispose(); Console.WriteLine("Press a key to exit the application."); Console.ReadKey(true); }
private async Task StartWatcher(CancellationToken token) { var response = await _client.ListClusterCustomObjectWithHttpMessagesAsync( group : Constants.Group, version : Constants.Version, plural : Constants.Plural, watch : true, timeoutSeconds : ((int)TimeSpan.FromMinutes(60).TotalSeconds), cancellationToken : token ); _watcher = response.Watch <HealthCheckResource, object>( onEvent: async(type, item) => await OnEventHandlerAsync(type, item, token) , onClosed: () => { _watcher.Dispose(); _ = StartWatcher(token); }, onError: e => _logger.LogError(e.Message) ); }