【发布时间】:2016-04-19 02:09:09
【问题描述】:
我正在使用 Dropbox 中的文件在服务器之间进行通信。一段时间后,我意识到在 Dropbox 内的文件上执行基本的File 操作时,每隔一段时间就会出现延迟。
我需要的是这样的:
public class MyFile
{
const int maxWaitCount = 60;
//..
/// <summary>
/// remove file - also has to work inside Dropbox directory
/// </summary>
/// <returns>0 for ok or error code</returns>
public int rm()
{
string name = Os.winInternal(FullName);
if (File.Exists(name))
{
File.Delete(name);
#region double check if file is gone
if (Ensure)
return awaitFileVanishing(name);
#endregion
}
return 0;
}
//..
private int awaitFileMaterializing(string fileName) //..
private int awaitFileVanishing(string fileName) //..
/// <summary>
/// Constructor: auto-ensure mode for file systems that do not synchronously wait for the end of an IO operation i.e. Dropbox
/// </summary>
/// <remarks>only use the ensure mode if it has to be guaranteed that the IO operation was completely done
/// when the method call returns; necessary e.g. for Dropbox directories since (currently) Dropbox first updates the
/// file in the invisible . folder and then asynchronously updates the visible file and all the remote copies of it</remarks>
/// <param name="filename"></param>
public MyFile(string filename)
{
Ensure = filename.ToLower().Contains("dropbox");
// ..
}
}
因为我需要一个快速的解决方案,所以我想出了一个解决方案,我将在下面给出我自己的问题的答案。但是,我可以很容易地想象你们中的一些人也遇到了这个问题,并找到了一个不同的、可能更引人注目的解决方案。请告诉我。
【问题讨论】:
标签: c# io dropbox windows-server