Код: Выделить всё
try
{
if (!Directory.Exists(monitoredDirectory))
{
MessageBox.Show($"The directory '{monitoredDirectory}' does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
fileSystemWatcher = new FileSystemWatcher
{
Path = monitoredDirectory,
NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.CreationTime,
Filter = "*.*",
EnableRaisingEvents = true
};
fileSystemWatcher.Created += OnDirectoryCreated;
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred during FileSystemWatcher initialization: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Ну, я пробовал отладку с помощью функций try catch, показывающих окно сообщений, когда что-то происходит. И я ожидаю, что fileSystemWatcher.Created += OnDirectoryCreated; будет выполнен и перейдет к OnDirectoryCreated() void.
Подробнее здесь: https://stackoverflow.com/questions/785 ... g-anything