.NET System.IO.FileSystemWatcher callback fails in compiled matlab code
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
2 Kommentare
per isakson
am 9 Aug. 2017
Bearbeitet: per isakson
am 9 Aug. 2017
Could this possibly be related to https://uk.mathworks.com/support/bugreports/details/560506?partial=collapsed?
Jan
am 22 Aug. 2017
[Moved from section for answers] md nahid wrote:
did you ever find a solution for this?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Standalone Applications finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!