本文整理汇总了C#中Watcher.Watch方法的典型用法代码示例。如果您正苦于以下问题:C# Watcher.Watch方法的具体用法?C# Watcher.Watch怎么用?C# Watcher.Watch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Watcher
的用法示例。
在下文中一共展示了Watcher.Watch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
var watcher =
new Watcher(
Environment.CurrentDirectory,
(s) => System.Console.WriteLine("Dir created " + s),
(s) => System.Console.WriteLine("Dir deleted " + s),
(s) => System.Console.WriteLine("File created " + s),
(s) => System.Console.WriteLine("File changed " + s),
(s) => System.Console.WriteLine("File deleted " + s));
watcher.ErrorNotifier((path, ex) => { System.Console.WriteLine("{0}\n{1}", path, ex); });
// Print strategy
System.Console.WriteLine(
"Will poll continuously: {0}",
watcher.Settings.ContinuousPolling);
System.Console.WriteLine(
"Poll frequency: {0} milliseconds",
watcher.Settings.PollFrequency);
System.Console.WriteLine(
"Evented directory create: {0}",
watcher.Settings.CanDetectEventedDirectoryCreate);
System.Console.WriteLine(
"Evented directory delete: {0}",
watcher.Settings.CanDetectEventedDirectoryDelete);
System.Console.WriteLine(
"Evented directory rename: {0}",
watcher.Settings.CanDetectEventedDirectoryRename);
System.Console.WriteLine(
"Evented file create: {0}",
watcher.Settings.CanDetectEventedFileCreate);
System.Console.WriteLine(
"Evented file change: {0}",
watcher.Settings.CanDetectEventedFileChange);
System.Console.WriteLine(
"Evented file delete: {0}",
watcher.Settings.CanDetectEventedFileDelete);
System.Console.WriteLine(
"Evented file rename: {0}",
watcher.Settings.CanDetectEventedFileRename);
watcher.Watch();
var command = System.Console.ReadLine();
if (command == "refresh")
watcher.ForceRefresh();
watcher.StopWatching();
}
示例2: button1_Click
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Starting watcher");
fileWatcher = new Watcher();
fileWatcher.Watch(textBoxFrom.Text, textBoxTo.Text);
}