1
我想用这种方式如何创建方法,直到检测到文件为止?
detectedFile = Wait(directory, filter);
最原始的办法是使用循环,像
while(true)
{
var found = Directory.EnumerateFiles(directory, filter).FirstOrDefault();
if(found != null) return found;
Thread.Sleep(1000);
}
有没有更好的方式来做到这一点?
你可以使用FileSystemWatcher而不是阻塞? http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx – Blorgbeard
其实,我想阻止 –
你仍然可以使用'FileSystemWatcher.OnCreated'来放置触发器? – Bolu