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

4 ビュー (過去 30 日間)
Matthew Reaves
Matthew Reaves 2017 年 1 月 18 日
コメント済み: Jan 2017 年 8 月 22 日
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 件のコメント
per isakson
per isakson 2017 年 8 月 9 日
編集済み: per isakson 2017 年 8 月 9 日
Jan
Jan 2017 年 8 月 22 日
[Moved from section for answers] md nahid wrote:
did you ever find a solution for this?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeStandalone Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by