Answered by:
Is it safe and recommended to use FileWatcher in a ASP.NET web application?

Question
-
User-1262796070 posted
We have a requirement to reload few custom configuration files, any time they are modified or new files with xxx.config naming convention are dropped into virtual folder of web.
We don't want write separate windows service for this purpose.
We want to start a file watcher on App_Start and start monitoring files that we are interested. Then based on when change notification happens, we will do some app specific logic (like updating database/session/cache data etc).
Questions:
1. I am not sure what are the implications of using .NET File Watcher in this scenario.
2. Is this best option or if there are any better options to this problem.
3. Is there a way/feature to set IIS/ASP.NET to watch specific files (ending.config or so ext) and recycle application -Similar to how ASP.NET watches web.config or .aspx files and recycle the app.
Wednesday, December 16, 2009 8:52 AM
Answers
-
User-952121411 posted
We don't want write separate windows service for this purpose.Why? I have built a Windows Service using a FileSystemWatcher and it worked perfectly. The problem is in your scenario based on your (3) questions and other information, using an ASP.NET application will not be proper for this process. The main difference is how the (2) differ in basic behavior. Windows Services are designed to be background workers that are always on and do tasks exactly like hosting a FileSystemWatcher.
An ASP.NET application on the other hand is not intended to be a service that sits and waits to run tasks, but an interactive interface for a user. You could run into all sorts of issues with trying to use an ASP.NET application like session timeout or browser shutdown to start with. Plus you are relying on a possibly unstable client machine with a browser to be the life of your process. Server machines with services are more apt to do this type of processing.
All of the logic you detailed does not need heavy user interaction and would be perfect for a Windows Service. If the reason you are avoiding creating a Windows Service is because you have never done one before, or think they are difficult, that is not a problem. Check out the following link which will get going creating and installing the service. The all you need to do is add the FileSystemWatcher logic you were already planning to create anyways.
Walkthrough: Creating a Windows Service Application in the Component Designer:
http://msdn.microsoft.com/en-us/library/zt39148a.aspx
Hope this helps!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 16, 2009 11:14 AM
All replies
-
User-952121411 posted
We don't want write separate windows service for this purpose.Why? I have built a Windows Service using a FileSystemWatcher and it worked perfectly. The problem is in your scenario based on your (3) questions and other information, using an ASP.NET application will not be proper for this process. The main difference is how the (2) differ in basic behavior. Windows Services are designed to be background workers that are always on and do tasks exactly like hosting a FileSystemWatcher.
An ASP.NET application on the other hand is not intended to be a service that sits and waits to run tasks, but an interactive interface for a user. You could run into all sorts of issues with trying to use an ASP.NET application like session timeout or browser shutdown to start with. Plus you are relying on a possibly unstable client machine with a browser to be the life of your process. Server machines with services are more apt to do this type of processing.
All of the logic you detailed does not need heavy user interaction and would be perfect for a Windows Service. If the reason you are avoiding creating a Windows Service is because you have never done one before, or think they are difficult, that is not a problem. Check out the following link which will get going creating and installing the service. The all you need to do is add the FileSystemWatcher logic you were already planning to create anyways.
Walkthrough: Creating a Windows Service Application in the Component Designer:
http://msdn.microsoft.com/en-us/library/zt39148a.aspx
Hope this helps!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, December 16, 2009 11:14 AM -
User-583524385 posted
If I understand the requirements correctly, the cache is exactly what you want to use. You can tie cached objects with dependencies, such as rehydrating the cached object when a file is modified.
Friday, December 18, 2009 10:00 AM