나는 내 게임에 대한 패치를 만드는 중입니다. patcher는 ftp 서버에있는 각 파일의 크기를 사용자의 컴퓨터에있는 로컬 파일과 비교하여 검사합니다. 다른 경우, ftp 서버에서 새 파일을 다운로드합니다.재귀 함수가 완료되었는지 확인하는 방법은 무엇입니까?
"업데이트 완료! X 파일이 업데이트되었습니다."라는 인쇄 메시지를 추가하고 싶습니다. 모든 파일을 검사했지만 함수가 어디에서 끝났습니까?
private void CheckForUpdates(string ftpPath, string localPath)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpPath);
request.Credentials = new NetworkCredential(ftpUser, ftpPass);
request.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
List<string> files = new List<string>();
string line = reader.ReadLine();
while (!string.IsNullOrEmpty(line))
{
if (line != "." && line != ".." && line != ".htaccess")
{
files.Add(line);
}
line = reader.ReadLine();
}
response.Close();
responseStream.Close();
reader.Close();
foreach (string file in files)
{
string newFtpPath = ftpPath + "/" + file;
string newLocalPath = localPath + "/" + file;
new Thread(() => AppendText("Checking " + newLocalPath + Environment.NewLine)).Start();
if (IsFile(newFtpPath))
{
if (File.Exists(newLocalPath))
{
if (!IsFileEqual(newFtpPath, newLocalPath))
{
new Thread(() => AppendText(file + " is out of date or corrupted. Patching in progress..." + Environment.NewLine)).Start();
new Thread(() => Download(newFtpPath, newLocalPath)).Start();
}
}
else
{
new Thread(() => AppendText(file + " is missing. Patching in progress..." + Environment.NewLine)).Start();
new Thread(() => Download(newFtpPath, newLocalPath)).Start();
}
}
else
{
if (!Directory.Exists(newLocalPath))
{
new Thread(() => AppendText(file + " is missing. Patching in progress..." + Environment.NewLine)).Start();
Directory.CreateDirectory(newLocalPath);
}
new Thread(() => CheckForUpdates(newFtpPath, newLocalPath)).Start();
}
}
}
메서드를 처음 호출 한 후 알 수 있습니다. 따라서 재귀 함수를 처음 호출 한 후 다음 실행 행. 나는 대개 고정 카운터에 넣어 무기한으로 재발하지 않도록한다. (테스트 할 때) –
여기 당신의 문제는 당신이 새 스레드에서 산란하고 있다는 것이다.나는 확실히 얼마나 많은 쓰레드를 생성하고 세마포어와 같은 것을 사용하는지 추적 할 것입니다. –
이것을 생각한 후에. 필연적으로 스레딩을 통한 재귀를 사용하지는 않을 것이므로 모든 종류의 문제가 첨부되어 상당히 복잡합니다. 나는 단지 플래그와 while 루프를 사용하여 업데이트를 다시 확인해야 할 필요성을 확인합니다. 또는 아마도 –