繁体   English   中英

如何等待c#中的外部程序创建rtf文件

[英]how to wait for a rtf file to be created by an external program in c#

我正在编写一个ac#程序,它等待外部程序创建的rtf文件然后操作它们。 我需要一个方法来等待rtf文件。 我试过while循环,但它降低了外部程序的速度我认为我应该使用FileSystemWatcher类,我不知道如何将它用于rtf文件。

var fsw = new FileSystemWatcher(yourDirectory, "*.rtf");

MSDN FileSystemWatcher构造函数

这应该让你开始。 我不知道如何使用它有点太模糊。 如果你发布了一些关于你尝试过的代码以及为什么它没有像你期望的那样工作,社区可以给你一个更好的答案。 如果没有,这里是FileSystemWatcherMSDN页面,其中包含您可以试验的代码。

FileSystemWatcher似乎非常适合。 只需按照此处所述http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx使用它并过滤您的确切文件名而不是“* .txt”。

System.IO.FileSystemWatcher watcher = new System.IO.FileSystemWatcher(directory, file_name);
System.IO.WaitForChangedResult result;    
result = watcher.WaitForChanged(System.IO.WatcherChangeTypes.Created);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM