如何使用WCF service-C#监视指定的文件夹大小 [英] How to monitor specified folder size using WCF service-C#

查看:52
本文介绍了如何使用WCF service-C#监视指定的文件夹大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发asp.net应用程序。

我需要监控

As Iam developing asp.net application.
I need to monitor

C:\Monitor

(文件夹)使用wcf服务的总大小当达到1GB限制时发出警报。它应该在后台进程中完成。



例如:我将限制设置为1GB。当

(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

C:\Monitor

文件夹达到800MB左右时,我应该提供警报信息。在IIS中托管时,如何在WCF服务或任何其他服务中使用。



我尝试过:



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.

推荐答案

您尝试使用WCF实现此目的的任何特定原因。我的理解可以通过Windows EXE或Windows服务实现。您可以使用filesystemwatcher并等待事件。在特定事件上检查大小并触发您的规则。作为参考,您可以查看 FileSystemWatcher.Changed Event(系统) .IO) [ ^ ]
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)[^]


如解决方案1中所述,您可以尝试FileSystemWatcher。但是在某些情况下,这个课程不可靠,你可能会错过任何活动。它的行为在所有支持的操作系统(XP,Win7,Win10等)中都不一致。此外,它可以在一个文件上触发多个更改事件以进行单个保存操作。在我们的例子中,我们最终使用一个定时扫描文件夹进行任何更改的计时器。我不能说这是最好的方法,但至少它比FileSystemWatcher更可靠和一致。也许您可以将这两者结合起来,以满足您的需求。祝你好运: - )。
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 :-).


这篇关于如何使用WCF service-C#监视指定的文件夹大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆