求一个思路 目的:网站启动的时候读取一个xml文件,将文件内容封装成类放到内存中。考虑到xml在网站运行期间可能被修改,故要定时去读该文件,并且更新内存中相关内容。请给思路,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 static void Main(string[] args) { FileSystemWatcher watch = new FileSystemWatcher(); watch.Path = @"D:\tmp"; watch.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Only watch text files. watch.Filter = "*.txt"; watch.Changed += new FileSystemEventHandler(OnChanged); watch.Created += new FileSystemEventHandler(OnChanged); watch.Deleted += new FileSystemEventHandler(OnChanged); watch.Renamed += new RenamedEventHandler(OnRenamed); watch.EnableRaisingEvents = true; Console.ReadLine(); } private static void OnChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. if(e.FullPath == @"D:\tmp\p.txt") Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); } private static void OnRenamed(object source, RenamedEventArgs e) { // Specify what is done when a file is renamed. if (e.FullPath == @"D:\tmp\p.txt") Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath); } 这个xml的作用是什么啊?你这样的设计可能本身就是花蛇添足。既然会更新,就是更新时对这个内存中的数据进行更新阿 xml的主要作用就是存放了一些组件的路径,程序读取组件路径,反射出实例。 本机程序上传到空间时出现的错误,100分求各位高手知道的指导下 远程API调用 数据保留问题 请教一个ajax.net的问题(按钮提交) 这个比较难的... WebRequest的使用问题 为什么sql中的in不起作用??? vs在调试网站时,打开的浏览器,能不能设置,比如设成MyIE? 请问怎么操作datagrid模板中的按钮?小妹在线等 [求助]请提供一下用VB。NET开发ASP。NET的电子图书、源代码以及寻找同盟者、QQ群 用过webdiyer的请进来帮我看看 菜鸟问题:如何取得一个目录的大小? ASP.NET (C#)能调用扫描仪吗 关于读取XML的问题
{
FileSystemWatcher watch = new FileSystemWatcher();
watch.Path = @"D:\tmp"; watch.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Only watch text files.
watch.Filter = "*.txt"; watch.Changed += new FileSystemEventHandler(OnChanged);
watch.Created += new FileSystemEventHandler(OnChanged);
watch.Deleted += new FileSystemEventHandler(OnChanged);
watch.Renamed += new RenamedEventHandler(OnRenamed); watch.EnableRaisingEvents = true; Console.ReadLine();
} private static void OnChanged(object source, FileSystemEventArgs e)
{
// Specify what is done when a file is changed, created, or deleted.
if(e.FullPath == @"D:\tmp\p.txt")
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); } private static void OnRenamed(object source, RenamedEventArgs e)
{
// Specify what is done when a file is renamed.
if (e.FullPath == @"D:\tmp\p.txt")
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
既然会更新,就是更新时对这个内存中的数据进行更新阿