필터 지우기
필터 지우기

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

조회 수: 3 (최근 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
Jan
Jan 2017년 8월 22일
[Moved from section for answers] md nahid wrote:
did you ever find a solution for this?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Getting Started with Microsoft .NET에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by