Application Restart for folder deleted,added,updated

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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’); HKLMSoftwareMicrosoftASP.NETFCNMode

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:

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x