Azzera filtri
Azzera filtri

.NET System.IO.​FileSystem​Watcher callback fails in compiled matlab code

3 visualizzazioni (ultimi 30 giorni)
I am running into an issue where System.IO.FileSystemWatcher appears to work when run in MATLAB but not when my MATLAB code is compiled into an executable. I've simplified my code to show an illustrative example. For simplification, assume that my object "app" only has a member property "textWatcher" which is of type System.IO.FileSystemWatcher. When I call the app constructor, I do the following:
% Check to make sure that any .NET commands are seen
disp('Is .NET Supported?:')
NET.isNETSupported
% Setup FileSystemWatcher
app.textWatcher = System.IO.FileSystemWatcher('C:\Users\reavemt1\Documents\drs');
app.textWatcher.Filter = 'CallbackTest.txt';
app.textWatcher.EnableRaisingEvents = true;
addlistener(app.textWatcher,'Changed',@(src,evnt)disp('textWatcher Callback Hit!'));
% Display the watcher object
app.textWatcher
% Check the class of the created object
class(app.textWatcher)
I'm using a diary so I can check that the print commands. As expected, here are the diary results from these lines of code:
Is .NET Supported?:
ans =
1
ans =
FileSystemWatcher with properties:
NotifyFilter: FileName, DirectoryName, LastWrite
EnableRaisingEvents: 1
Filter: [1x1 System.String]
IncludeSubdirectories: 0
InternalBufferSize: 8192
Path: [1x1 System.String]
Site: []
SynchronizingObject: []
Container: []
ans =
System.IO.FileSystemWatcher
So it appears that the object was created successfully. However, when I change the file that the FileSystemWatcher is monitoring, the program crashes immediately without executing the callback function. When this same code is run in MATLAB, the program works fine, and when the file is changed, the text "textWatcher Callback Hit!" is printed as expected.
What do I need to add to my compiled project to make this work, or is there something more sinister lurking?

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by