c#file.move服务在网络上缓慢



我创建了一个将目录中的某些文件类型移至另一个文件的服务,在本地可以很好地工作,并且在我的网络上可以很好地工作。在另一个网络上的工作速度令人难以置信的速度(一个500MB文件需要6 1/2分钟),但是复制并通过Explorer粘贴到文件夹中的同一文件在大约30/40秒内完成。

摘要发生文件移动的地方。

currentlyProcessing.Add(currentFile.FullName);
try
{
    eventMsg("Attempting to move file","DEBUG");
    File.Move(oldFilePath, newFilePath);
    eventMsg("File Moved successfully","DEBUG");

}
catch (Exception ex)
{
    eventMsg("Cannot Move File another resource is using it", "DEBUG");
    eventMsg("Move File Exception : " + ex, "DEBUG");
}
finally
{ 
    if(File.Exists(currentFile.FullName + ".RLK"))
    {
        try
        {
            File.Delete(currentFile.FullName + ".RLK");
        }
        catch (IOException e)
        {
            eventMsg("File Exception : " + e, "DEBUG");
        }
    }
    currentlyProcessing.Remove(oldFilePath);
}

我担心代码很好(因为它在其他网络上的预期工作),因此问题可能是网络,某种形式或形式。是否有人有任何常见的提示可以检查,该服务作为本地系统(或网络服务)运行,并且似乎没有访问问题。其他因素会影响这一点(除网络/硬件以外)。

我想要的是,它的传输速度与我在Explorer中见过的类似的传输速度。任何指针都非常感谢。

首先互相检查以检查延迟,以便您可以查看它是否在网络中在全球范围内或您的软件是某种内容。

cmd ping 192.168.1.12 -n 10

如果网络上的问题,请遵循以下内容:

  1. 重新启动轮毂/路由器
  2. 是PC的一台使用WiFi带有低信号的WiFi?
  3. 是否有任何抗病毒可以打开并监视网络活动?

如果以上都无法解决您的问题,请尝试使用Wireshark进一步研究该问题。

对于尺寸如此巨大的文件,我建议在可能的情况下将其拉开,尤其是因为网络延迟始终是通过Internet上传/下载文件的重要因素。您可以使用 system.io.io.packaging 将文件进行zip。在此处使用System.io.packaging在此处查看以生成zip文件,特别是:

using (Package zip = System.IO.Packaging.Package.Open(zipFilename, FileMode.OpenOrCreate))
        {
            string destFilename = ".\" + Path.GetFileName(fileToAdd);
            Uri uri = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.Relative));
            if (zip.PartExists(uri))
            {
                zip.DeletePart(uri);
            }
            PackagePart part = zip.CreatePart(uri, "",CompressionOption.Normal);
            using (FileStream fileStream = new FileStream(fileToAdd, FileMode.Open, FileAccess.Read))
            {
                using (Stream dest = part.GetStream())
                {
                    CopyStream(fileStream, dest);
                }
            }
        }

另外,如果可能的话,您也可以像其他用户一样提到其他用户。查看CodePlex上的Renci SSHNET库。

最新更新