目的:
网站启动的时候读取一个xml文件,将文件内容封装成类放到内存中。考虑到xml在网站运行期间可能被修改,故要定时去读该文件,并且更新内存中相关内容。请给思路,谢谢

解决方案 »

  1.   

    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);
            }
      

  2.   

    这个xml的作用是什么啊?你这样的设计可能本身就是花蛇添足。
    既然会更新,就是更新时对这个内存中的数据进行更新阿
      

  3.   

    xml的主要作用就是存放了一些组件的路径,程序读取组件路径,反射出实例。