.NET System.IO.FileSystemWatcher callback fails in compiled matlab code
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
per isakson
el 9 de Ag. de 2017
Editada: per isakson
el 9 de Ag. de 2017
Could this possibly be related to https://uk.mathworks.com/support/bugreports/details/560506?partial=collapsed?
Jan
el 22 de Ag. de 2017
[Moved from section for answers] md nahid wrote:
did you ever find a solution for this?
Respuestas (0)
Ver también
Categorías
Más información sobre Getting Started with Microsoft .NET en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!