Je veux télécharger un fichier à partir d'un serveur FTP dans l'autre thread. Le problème est, ce thread provoque que mon application est gelée. Ici vous avez le code, qu'est-ce que je fais mal? Toute aide sera reconnaissant par :)MyThread.Join() bloque l'ensemble de l'application. Pourquoi?
(Bien sûr, je veux arrêter de boucler jusqu'à ce que le fil se termine « ReadBytesThread ».) Je fais un nouveau fil:
DownloadThread = new Thread(new ThreadStart(DownloadFiles));
DownloadThread.Start();
private void DownloadFiles()
{
if (DownloadListView.InvokeRequired)
{
MyDownloadDeleg = new DownloadDelegate(Download);
DownloadListView.Invoke(MyDownloadDeleg);
}
}
private void Download()
{
foreach (DownloadingFile df in DownloadingFileList)
{
if (df.Size != "<DIR>") //don't download a directory
{
ReadBytesThread = new Thread(() => {
FileData = sendPassiveFTPcmd("RETR " + df.Path + "/" + df.Name + "\r\n");
FileStream fs = new FileStream(@"C:\Downloads\" + df.Name, FileMode.Append);
fs.Write(FileData, 0, FileData.Length);
fs.Close();
});
ReadBytesThread.Start();
(here->) ReadBytesThread.Join();
MessageBox.Show("Downloaded");
}
}
}