c# - Why is my FileSystemWatcher flag not updating in my razor view -
i have mvc 5 project set run iis express on vs2015. makes use of filesystemwatcher monitor folder , populate list accordingly. every 5 seconds check state of folderchanged flag. when true want alert user , reset flag false. have verified filesystemwatcher works , folder being correctly monitored. problem folderchanged flag never seen true in razor view updated in do_something method. fear may missing fundamentally simple have no idea what. appreciated.
model class:
public class logfileparser { public list<string> folderrecords { get; set; } public bool folderchanged { get; set; } private filesystemwatcher folder_watcher; public logfileparser() { //set list folder path , filesystemwatcher folder_watcher.changed += do_something(); folder_watcher.enableraisingevents = true; } private void do_something(object sender, filesystemeventargs e) { //populate folderrecords list folderchanged = true; } }
controller class:
public class democontroller : controller { public actionresult test() { logfileparser log_file_parser = new logfileparser(); return view(log_file_parser); } [httppost] public actionresult test(logfileparser log_file_parser) { return view(log_file_parser); } }
razor view:
@model monitoringmachineparams.models.logfileparser @{ viewbag.title = "test"; layout = "~/views/shared/_layout.cshtml"; } <h2>test</h2> <script type="text/javascript"> $(document).ready(function () { window.setinterval(function () { update(); }, 5000); }); function update() { @if (model.folderchanged){ model.folderchanged = false; html.hiddenfor(m => m.folderchanged); <text>alert("hello");</text> }} </script>
i think don't understand how web works. once render view , send client, disconnects server. unless make ajax requests server, or otherwise retrieve new data server, folder can change day long, client not aware of it.
your entire design should change. should have action can return value indicating if folder changed, , client code retrieve data , act on it.
Comments
Post a Comment