Как сделать последовательное выполнение методов?
Есть метод Method_A
и Method_B
, они должны выполниться последовательно: сначала Method_A
затем Method_B
, причем если метод выдал ошибку, не выполнился, или возникли еще какие-либо проблемы, необходимо повторить выполнение метода.
Метод А
static void download()
{
Console.WriteLine("Beginning to download results..");
FtpClient ftp = new FtpClient();
sFTP sftp = new sFTP();
ftp.PassiveMode = true;
int TimeOUT = 1000;
do
{
ftp.Connect(TimeOUT, "host", 21);
ftp.Login(TimeOUT, @"log", "pass");
}
while (ftp.IsConnected == false);
ftp.ChangeDirectory(TimeOUT, @"directory");
foreach (FtpItem item in ftp.GetDirectoryList(TimeOUT))
{
if (item.ItemType == FtpItemType.File && !System.IO.File.Exists(@"path" + item.Name))
{
ftp.GetFile(TimeOUT, @"path" + item.Name, @"path" + item.Name);
Console.WriteLine("Скачан файл - " + item.Name);
}
}
ftp.Disconnect(TimeOUT);
Console.WriteLine("The results have been downloaded");
}
Метод В
static void upload()
{
Console.WriteLine("Beginning to upload files to FTP-server..");
FtpClient ftp = new FtpClient();
sFTP sftp = new sFTP();
ftp.PassiveMode = true;
int TimeOUT = 1000;
do
{
ftp.Connect(TimeOUT, "host", 21);
ftp.Login(TimeOUT, @"log", "pass");
}
while (ftp.IsConnected);
var dirLocal = new DirectoryInfo(@"directory");и
foreach (FileInfo file in dirLocal.GetFiles())
{
string fileName = Path.GetFileNameWithoutExtension(file.FullName) + Path.GetExtension(file.FullName);
ftp.PutFile(TimeOUT, "path" + fileName, @"path" + fileName);
Console.WriteLine("Файл - " + fileName + " " + "загружен на FTP сервер");
string spath = @"path" + fileName;
string dpath = @"path" + fileName;
File.Move(spath, dpath);
Console.WriteLine("Файл - " + fileName + " " + "перемещен");
}
ftp.Disconnect(TimeOUT);
Console.WriteLine("The files have been uploaded to FTP server");
}
a(); b();
- методы выполнятся последовательно. При чём тут многопоточность?Task.Run && ContinueWith
Помогут?