Click here to Skip to main content
15,746,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As Iam developing application.
I need to monitor
(folder)Total size using wcf service and alert when it reaches 1GB limit. It should be done in background process.

For example: I have set limit as 1GB. When
folder reaches near 800MB , I should provide me alert message. How it is possible in WCF Service or any other service, when hosting in IIS.

What I have tried:

I have googled so many stuff, Currently it doesn't match my requirement.
Updated 29-Jan-17 19:26pm
Suvendu Shekhar Giri 30-Jan-17 0:49am    
Not Clear!
Please spend some more time describing your problem clearly.
Also share what have you tried so far.

Any specific reason you are trying to achieve this using WCF. What I understand this can be achieved by Windows EXE or Windows Service. You can use filesystemwatcher and wait for event. On specific event check the size and trigger your rule. For reference you can check FileSystemWatcher.Changed Event (System.IO)[^]
Share this answer
vinodh muthusamy 30-Jan-17 1:06am    
Iam working in web based application.

Link which you have shared is about create,changed,delete. But i need to monitor folder Size.
Ashwin. Shetty 30-Jan-17 1:12am    
Web base app can only validate the size on request to a server. if you try to run it in the background it won't be reliable. IIS may also timeout and stop the execution thread. If I would be in your place I would have hosted WCF service inside Windows Service (Self-hosted) and expose WCF API which will take two parameters ( Folder to monitor & Email Id for an alert). Monitor folder which was received in the separate thread and alert user based on the threshold. This WCF service will be called internally from my website.

You are right link which I have shared is for create, change and delete file. Isnt that will resize your folder ??
vinodh muthusamy 30-Jan-17 1:39am    
Suggestion which you have given me, matches exactly my requirement. Could you provide any sample code or link to watch.
Ashwin. Shetty 30-Jan-17 1:55am    
It will be difficult to point you to complete code, but you may look for wcf self hosting. After validation from WCF service endpoint raise event which is registered by windows service internally. Register method to this event which will create a new thread and attach function which can carry out above task
As suggested in Solution 1 you can try FileSystemWatcher. However in some cases this class is not reliable and you may miss events & its behavior is not consistent across all supported OSes(XP,Win7,Win10 etc). Moreover it can fire multiple change events for single save operation on one file. In our case we ended up using a timer which periodically scans folder for any change. I can not say it is best approach but at least it was more reliable and consistent than FileSystemWatcher. May be you can combine both of these to best suite to your needs. Good luck :-).
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900