私はDropbox内のファイルを使用してサーバー間で通信しています。しばらくすると、Dropbox内のファイルに対して実行されるときに、基本的には遅れがあることに気が付きました(File
)。私は必要なものDropbox内のファイルが実際に削除されたことを確認するにはどうすればよいですか?
は、このようなものです:私は、迅速なソリューションを必要としているので
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");
// ..
}
}
、私は以下の自分の質問への答えとして提示しています1を思い付きました。しかし、あなたの中にはこの問題もあって、おそらくもっと魅力的な解決法が見つかったと簡単に想像することができます。私にお知らせください。
代わりのスレッドを寝て、私はスレッドが完全に他の何かをすることによって利用することができるように、非同期遅延を使用することをお勧めだと思います。 – Hendry