Application Restart for folder deleted,added,updated

我与影子孤独终老i 提交于 2019-12-31 05:59:25

问题


Modifying, adding, or deleting certain types of files within the application's known folders will cause the application to restart.But when Log file in application is updated,why application is not restart. Then

PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public |  BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { }); 

With these changes, I can create/modify/delete folders without causing the application to restart. But this code is for all application's known folders.I want to know is for one folder without causing the application restart.


回答1:


Your problem is because as soon as you modify, or delete any file from the applications directory, it is causing appDomain restart in order to load the changes. You got 4 options as far as I could look for:

  1. Disable directory monitoring, which you have already tried.
  2. Create a Virtual directory under the application and point this to a folder outside the application folder. Move the content that needs to be changed to this folder and can make changes.
  3. Use out of process session.
  4. Modify the registry to disable monitoring as given (Not recommended):

Registry information

loadTOCNode(3, 'resolution'); HKLM\Software\Microsoft\ASP.NET\FCNMode

The following table lists possible values for the FCNMode DWORD value and the behavior that is associated with each value.

Value Behavior Does not exist This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory. 0 or greater than 2 This is the default behavior. For each subdirectory, the application will create an object that will monitor the subdirectory.

1 The application will disable File Change Notifications (FCNs). [:)].

2 The application will create one object to monitor the main directory. The application will use this object to monitor each subdirectory.

The above method is take from here

Also, you can go through the following links for more information:

  • http://forums.asp.net/t/966593.aspx/1
  • http://blogs.msdn.com/b/toddca/archive/2005/12/01/499144.aspx
  • http://weblogs.asp.net/owscott/archive/2006/02/21/438678.aspx
  • http://aspadvice.com/blogs/joteke/archive/2006/02/22/15299.aspx

Well, this might be able to help with your issue, I could not find out anything about stopping the appDomain change monitoring for a specific folder. Either it would monitor the changes or not. Hope this helps. Cheers.



来源:https://stackoverflow.com/questions/12244530/application-restart-for-folder-deleted-added-updated

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