本文整理汇总了C#中System.IO.FileSystemWatcher.BeginInit方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystemWatcher.BeginInit方法的具体用法?C# FileSystemWatcher.BeginInit怎么用?C# FileSystemWatcher.BeginInit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileSystemWatcher
的用法示例。
在下文中一共展示了FileSystemWatcher.BeginInit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileWatcher
public FileWatcher(string directory, string filter)
{
_dispatcher = Dispatcher.CurrentDispatcher;
_watcher = new FileSystemWatcher();
_watcher.BeginInit();
_watcher.Path = directory;
_watcher.Filter = filter;
_watcher.IncludeSubdirectories = false;
_watcher.InternalBufferSize = InitialBufferSize;
_watcher.NotifyFilter
= NotifyFilters.DirectoryName
| NotifyFilters.FileName
| NotifyFilters.LastWrite
| NotifyFilters.Attributes
| NotifyFilters.Security
| NotifyFilters.Size;
// note: all events are on threadpool threads!
_watcher.Created += onCreated;
_watcher.Deleted += onDeleted;
_watcher.Changed += onChanged;
_watcher.Renamed += onRenamed;
_watcher.Error += onError;
_watcher.EndInit();
_watcher.EnableRaisingEvents = true;
}
示例2: SNTemplateManager
private SNTemplateManager(string snTmplRuleFilePath)
{
rulesfileWatcher = new FileSystemWatcher();
rulesfileWatcher.BeginInit();
rulesfileWatcher.EnableRaisingEvents = true;
rulesfileWatcher.Filter = "*.rules";
rulesfileWatcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;
rulesfileWatcher.Path = snTmplRuleFilePath;
rulesfileWatcher.Changed += new FileSystemEventHandler(ruleFileWatcher_Changed);
rulesfileWatcher.EndInit();
}
示例3: DeserializedRuleSetsManager
private DeserializedRuleSetsManager()
{
snTmplRuleFilePath = ConfigurationManager.AppSettings["RulePath"].ToString();
irm = RuleSetManagerFactory.CreateFileRuleSetManager();
rulesfileWatcher = new FileSystemWatcher();
rulesfileWatcher.BeginInit();
rulesfileWatcher.EnableRaisingEvents = true;
rulesfileWatcher.Filter = "*.rules";
rulesfileWatcher.NotifyFilter = System.IO.NotifyFilters.LastWrite;
rulesfileWatcher.Path = snTmplRuleFilePath;
rulesfileWatcher.Changed += new FileSystemEventHandler(ruleFileWatcher_Changed);
rulesfileWatcher.EndInit();
}
示例4: OnStart
protected override void OnStart(string[] args)
{
Thread.Sleep(15000);
log = new EventLog();
log.Source = "S1 Payment Operator Service";
setting = new Setting();
files = new ArrayList();
fileWatcher = new FileSystemWatcher();
fileWatcher.BeginInit();
fileWatcher.IncludeSubdirectories = false;
fileWatcher.Filter = "*.txt";
fileWatcher.Path = setting.incomingFolder;
fileWatcher.Created += new FileSystemEventHandler(OnFileCreated);
fileWatcher.EnableRaisingEvents = true;
fileWatcher.EndInit();
}
示例5: AddWatcher
public void AddWatcher(string path)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Created += new FileSystemEventHandler(fileCreated);
watcher.Changed += new FileSystemEventHandler(fileChanged);
watcher.Deleted += new FileSystemEventHandler(fileDeleted);
watcher.Renamed += new RenamedEventHandler(fileRenamed);
watcher.Path = @path;
watcher.EnableRaisingEvents = true;
watcher.IncludeSubdirectories = true;
watcher.BeginInit();
_watchers.Add(watcher);
_directories.Add(new DirectoryInfo(path));
WriteXML();
}
示例6: Watch
public IDisposable Watch(DirectoryInfo scriptPath)
{
var watcher = new FileSystemWatcher(scriptPath.FullName);
watcher.BeginInit();
watcher.Path = scriptPath.FullName;
watcher.EnableRaisingEvents = true;
watcher.Error += OnError;
watcher.Changed += OnChanged;
watcher.Created += OnCreated;
watcher.Deleted += OnDeleted;
watcher.Renamed += OnRenamed;
watcher.EndInit();
return new Disposable(() => watcher.Dispose());
}
示例7: Watcher
public Watcher(string path, Action<string> receiver)
{
// important to append the path with a directory separator,
// so that stripping works as expected!
if (!path.EndsWith(DirectorySeparatorString))
path += DirectorySeparatorString;
_path = path;
_receiver = receiver;
_watcher = new FileSystemWatcher();
_watcher.BeginInit();
_watcher.Filter = string.Empty;
_watcher.IncludeSubdirectories = true;
_watcher.InternalBufferSize = InitialBufferSize;
_watcher.Path = path;
_watcher.NotifyFilter
= NotifyFilters.DirectoryName
| NotifyFilters.FileName
| NotifyFilters.LastWrite
// we want attributes to catch error-fixups
| NotifyFilters.Attributes
| NotifyFilters.Security;
// we assume that size changes are covered by LastWrite
// | NotifyFilters.Size;
// note: all events are on threadpool threads!
_watcher.Created += onCreated;
_watcher.Deleted += onDeleted;
_watcher.Changed += onChanged;
_watcher.Renamed += onRenamed;
_watcher.Error += onError;
_watcher.EndInit();
_watcher.EnableRaisingEvents = true;
}
示例8: ListenForChanges
public static void ListenForChanges(string currentDirectory)
{
var watcher = new FileSystemWatcher(currentDirectory)
{
NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.Size | NotifyFilters.LastWrite,
EnableRaisingEvents = true,
IncludeSubdirectories = true,
InternalBufferSize = 16777216
};
watcher.BeginInit();
watcher.Changed += watcher_Changed;
watcher.Created += watcher_Changed;
watcher.Deleted += watcher_Changed;
watcher.Renamed += watcher_Changed;
watcher.EndInit();
while (true)
{
// begin event loop for watcher
System.Threading.Thread.Sleep(100);
ProcessQueueItem();
}
}
示例9: CreateFileSystemWatcher
/// <summary>
/// Creates the instance of <see cref="FileSystemWatcher" /> used
/// to monitor the file system.
/// </summary>
/// <returns>
/// An instance of <see cref="FileSystemWatcher" /> that will be
/// used to monitor the directory for the creation/modification
/// of log files.
/// </returns>
/// <remarks>
/// <see cref="CreateFileSystemWatcher" /> will be called from within
/// a synchronized context so derived classes should not attempt to
/// perform any additional synchronization themselves.
/// </remarks>
protected virtual FileSystemWatcher CreateFileSystemWatcher()
{
Contract.Ensures(Contract.Result<FileSystemWatcher>() != null);
var watcher = new FileSystemWatcher();
watcher.BeginInit();
watcher.Changed += this.watcher_Changed;
watcher.Created += this.watcher_Created;
watcher.EnableRaisingEvents = true;
watcher.Filter = this.Name + "_*.txt";
watcher.IncludeSubdirectories = false;
watcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite
| NotifyFilters.DirectoryName | NotifyFilters.FileName;
watcher.Path = this.Path;
watcher.EndInit();
return watcher;
}
示例10: InitLoadBackupJobs
private void InitLoadBackupJobs()
{
LoadBackupJobs();
_backupJobsFileSystemWatcher = new FileSystemWatcher();
if (_backupJobsFileSystemWatcher != null) return;
_backupJobsFileSystemWatcher = new FileSystemWatcher(GlobalSettings.AppDataSettingsPath);
_backupJobsFileSystemWatcher.BeginInit();
_backupJobsFileSystemWatcher.Created += FileSystemWatcherEvent;
_backupJobsFileSystemWatcher.Renamed += FileSystemWatcherRenamed;
_backupJobsFileSystemWatcher.Deleted += FileSystemWatcherEvent;
_backupJobsFileSystemWatcher.Changed += FileSystemWatcherEvent;
_backupJobsFileSystemWatcher.IncludeSubdirectories = true;
_backupJobsFileSystemWatcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.CreationTime | NotifyFilters.LastWrite | NotifyFilters.FileName;
_backupJobsFileSystemWatcher.EnableRaisingEvents = true;
_backupJobsFileSystemWatcher.EndInit();
}
示例11: AttachToSystem
public void AttachToSystem()
{
#if MONO && DEBUG
return;
#endif
if (_fileSystemWatcher != null) return;
_fileSystemWatcher = new FileSystemWatcher(ProjectPath);
_fileSystemWatcher.BeginInit();
_fileSystemWatcher.Created += FileSystemWatcherCreated;
_fileSystemWatcher.Renamed += FileSystemWatcherRenamed;
_fileSystemWatcher.Deleted += FileSystemWatcherDeleted;
_fileSystemWatcher.IncludeSubdirectories = true;
_fileSystemWatcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName;
_fileSystemWatcher.EnableRaisingEvents = true;
_fileSystemWatcher.EndInit();
}
示例12: OnStart
protected override void OnStart(string[] args)
{
try
{
Log("Service", "Start");
watcher = new FileSystemWatcher();
watcher.BeginInit();
watcher.IncludeSubdirectories = true;
watcher.Path = ResourcePath;
watcher.Created += Watcher_Created;
watcher.EnableRaisingEvents = true;
watcher.EndInit();
Log("Watching", "Start");
Log("Calculating", "Start");
DirectoryInfo info = new DirectoryInfo(ResourcePath);
var dirs = info.GetDirectories("视频", SearchOption.AllDirectories);
foreach (var dir in dirs)
{
var files = dir.GetFiles().Where(o =>
o.Name.EndsWith(".avi", StringComparison.OrdinalIgnoreCase) ||
o.Name.EndsWith(".mpg", StringComparison.OrdinalIgnoreCase) ||
o.Name.EndsWith(".mpeg", StringComparison.OrdinalIgnoreCase) ||
o.Name.EndsWith(".rm", StringComparison.OrdinalIgnoreCase) ||
o.Name.EndsWith(".rmvb", StringComparison.OrdinalIgnoreCase) ||
o.Name.EndsWith(".wmv", StringComparison.OrdinalIgnoreCase)).ToList();
var table = engine.OpenXTable<string, ConvertingResource>("Video");
foreach (var file in files)
{
var path = file.FullName;
var target = path.Substring(0, path.LastIndexOf('.')) + TagetExtension;
if (!File.Exists(target))
{
table[path] = new ConvertingResource { Target = target, Started = false };
Log("Todo", string.Format("{0} --> {1}", path, target));
}
}
engine.Commit();
}
Log("Calculating", "Calculated");
StartConvert();
}
catch (Exception exception)
{
try { watcher.Dispose(); } catch { }
Log("Error", exception.StackTrace.ToString(CultureInfo.InvariantCulture));
}
}
示例13: CreateFileSystemWatcher
protected FileSystemWatcher CreateFileSystemWatcher(string directory)
{
//Console.WriteLine("Watcher creating {0}", directory);
var watcher = new FileSystemWatcher()
{
Path = directory,
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName,
Filter = FileFilter,
IncludeSubdirectories = true
};
watcher.BeginInit();
watcher.Changed += OnModified;
watcher.Created += OnModified;
watcher.Deleted += OnModified;
watcher.Renamed += OnModified;
watcher.Error += WatcherOnError;
watcher.EndInit();
watcher.EnableRaisingEvents = true;
//Console.WriteLine("Watcher created {0}", directory);
return watcher;
}
示例14: InitializeFileSystemWatcher
void InitializeFileSystemWatcher(string path)
{
if (folderWatcher != null)
{
folderWatcher.Dispose();
}
folderWatcher = new FileSystemWatcher(path, "*.bin");
folderWatcher.BeginInit();
folderWatcher.Changed += OnFolderWatcherChanged;
folderWatcher.Created += OnFolderWatcherCreated;
folderWatcher.Deleted += OnFolderWatcherDeleted;
folderWatcher.EnableRaisingEvents = true;
folderWatcher.IncludeSubdirectories = false;
folderWatcher.SynchronizingObject = this;
folderWatcher.EndInit();
}
示例15: Main
static void Main(string[] args)
{
var path = args.Length == 0 ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Diablo III\Screenshots" : args[0];
if (args.Length == 3)
{
Size = new Rectangle(int.Parse(args[1].Split('x')[0]), int.Parse(args[1].Split('x')[1]),
int.Parse(args[2].Split('x')[0]), int.Parse(args[2].Split('x')[1]));
ResetSize = false;
}
Console.WriteLine("Registering filesystem events. ({0})", path);
watcher = new FileSystemWatcher(path, "*.jpg");
watcher.BeginInit();
watcher.EnableRaisingEvents = true;
watcher.Created += WatcherOnCreated;
watcher.EndInit();
while (true)
{
Thread.Sleep(1000);
}
}