Delay in loading AdDomain application when changing folders

I am developing an ASP.NET 4 application and using full IIS also during development (for several reasons, one of which I use several domains pointing to the application).

When I create a project in Visual Studio, IIS processes the AppDomain and loads the newly created one, but now I have a problem that it does it "fast."
I have some scripts on my page that launch App-Startup as soon as they are processed (for example, constantly open SignalR channels), and therefore a new AppDomain is already created when only half of my project is built, and therefore it restarts a second time. then it actually crashes because I have PreApplicationStartMethod copying some DLL plugins to the Shadow-Copy directory, but the β€œold DLL files” are still blocked by the first AppDomain.
If I then wait ~ 10, everything will be fine, and my "new AppDomain" will start.
Although I decided to solve this problem by simply asking IIS to wait with the acceptance for a few seconds so that the assembly would complete after detecting changes in the bin folder.

So, to my main question:
Is it possible to defer reprocessing of AppDomain in IIS?

+6
source share
2 answers

If you cannot postpone restarting AppDomain, you can disable it.

There is a Change Change File (FCN) behavior that can be disabled.

Registry

Initially, this is an entry in the DWORD registry in HKLM\Software\Microsoft\ASP.NET\FCNMode , setting it to 1 to disable it .

Code (hack) before .NET Framework 4.0

This hack can work with frameworks 2.0-3.5 and 4.0.

 //Disable AppDomain restart on file change System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static); object fcm = p.GetValue(null, null); System.Reflection.MethodInfo m = fcm.GetType().GetMethod("Stop", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); m.Invoke(fcm, new object[] { }); 

Put it in your Global.asax Application_Start . See here .

If you want to disable monitoring for specific paths or files, you can use the StopMonitoringFile or StopMonitoringPath from FileChangesMonitor . However, the Bin directory is a special directory and may be immune to these two methods.

At least you can play in the _dirMonSpecialDirs field and call StopMonitoring() in your Bin directory.

.NET Framework 4.5

In the .NET Framework 4.5, the HttpRuntimeSection.FcnMode property exists . There is not much documentation, but you can use <httpRuntime fcnMode="Disabled"/> .

+14
source

Found an article explaining this: http://www.ipreferjim.com/2012/04/asp-net-appdomains-and-shadow-copying/

The settings I was looking for are waitChangeNotification and maxWaitChangeNotification as httpRuntime attributes.

Unfortunately, it seems that I have not solved my problem - I need to investigate more ...

+2
source

Source: https://habr.com/ru/post/951051/


All Articles