Why doesn't the ServiceStack Razor FileSystemWatcher work on Mono + Mac OS X?

女生的网名这么多〃 提交于 2019-12-06 03:22:21

After investigating and testing various things out, I found several older bug reports against Mono about failing FileSystemWatcher functionality.

The workaround to the problem is found in the Mono source: https://github.com/mono/mono/blob/master/mcs/class/System/System.IO/FileSystemWatcher.cs

string managed = Environment.GetEnvironmentVariable ("MONO_MANAGED_WATCHER");
...
if (String.Compare (managed, "disabled", true) == 0)
    NullFileWatcher.GetInstance (out watcher);
else
    DefaultWatcher.GetInstance (out watcher);

If you set the environment variable MONO_MANAGED_WATCHER to anything (I set it to "enabled") then it will use the DefaultWatcher which is a managed implementation, and it works on Mac OS X.

So during my application startup, I added:

Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "enabled");

and voila, my Razor views are recompiled after I save a new version. :)

it works but mono begins to consume a lot of CPU time: ~70% of one core.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!