使用远程文件覆盖本地文件会导致Unity Standalone Application冻结

时间:2013-05-09 22:46:05

标签: c# unity3d

我是一名开发人员,使用Unity游戏引擎尝试使用FTP服务器中的文件覆盖本地文件。我正在使用System.IO.File.WriteAllBytes函数来执行此操作。

当我启动应用程序并触发已更新的代码时,我的应用程序将冻结。

在我的Windows窗体中,代码到达此处,它使用WebClient实例下载文件,如果它大于本地文件则覆盖它:

public void downloadFile (WebClient webClient, string urlAddress, 
    string location, byte[] localFile)
{
        webClient.Proxy = null;
        webClient.Credentials = new NetworkCredential("<user>", "<pass>");
        byte[] fileData = webClient.DownloadData("ftp://"+ urlAddress);
        /*
         * Only download if bytes of remote file 
         * is larger than bytes of local file
         */
        if (fileData.Length > localFile.Length)
        {
            File.WriteAllBytes(location, fileData);
        }
}

使用FileStream也会导致应用程序冻结。

FileStream _FileStream = new FileStream(location, FileMode.Create, FileAccess.Write);
_FileStream.Write(fileData, 0, fileData.Length);
_FileStream.Close();

我还尝试将所有需要更新的文件写入Temporary文件夹,然后使用File.Copy

我认为要正确覆盖文件是做什么的?

0 个答案:

没有答案
相关问题