No me lanza los eventos filesystemwatcher c# mono
Publicado por Alejandro (2 intervenciones) el 08/10/2019 19:03:16
Hola buenas, estoy intentado crear en ubuntu un programa servidor que controle los archivos de un directorio, pero no me lanza los eventos, lo he depurado y funciona pero sin lanzar los eventos, con la variable de entorno MONO_MANAGED_WATCHER he probado a configurarla como true, false, disabled, enabled, con 1, 2, 3 y 4 que leeído varias formas pero ninguna parece funcionar, que puede ser le instale las lib de gamin y fam pero nada, aqui el codigo.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
public static void Main(string[] args)
{
Thread th2 = new Thread(() =>
{
while (true)
{
MonitorDirectory();
Thread.Sleep(1000);
}
});
th2.Start();
}
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public static void MonitorDirectory()
{
Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "2");
using (FileSystemWatcher fileSystemWatcher = new FileSystemWatcher())
{
fileSystemWatcher.BeginInit();
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.Path = "/home/brok4d/ftp";
fileSystemWatcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
fileSystemWatcher.Changed += FileSystemWatcher_Changed;
fileSystemWatcher.Created += FileSystemWatcher_Created;
fileSystemWatcher.Deleted += FileSystemWatcher_Deleted;
fileSystemWatcher.InternalBufferSize = 32768;
fileSystemWatcher.Filter = "*.zip";
fileSystemWatcher.EnableRaisingEvents = true;
fileSystemWatcher.EndInit();
Console.WriteLine("funciona");
}
}
public static void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Changed)
{
Console.WriteLine("changed: " + e.FullPath);
}
}
public static void FileSystemWatcher_Created(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Created)
{
Console.WriteLine("created: " + e.FullPath);
}
}
public static void FileSystemWatcher_Deleted(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Deleted)
{
Console.WriteLine("delated: " + e.FullPath);
}
}
Valora esta pregunta


0