My problem is like this. I have several functions:
public List<FtpDirectoryEntry> ListDirectory();
public bool DirectoryExists(string dir);
public void UploadFile(string file);
public void UploadFiles(params string[] files);
I want to write a function to run these functions 5 times. If we can not get result in 5 times, it will throw exception.
public void CheckFunctionWithTrials( function X)
{
for (int i = 0; i < 5; i++)
{
try
{
X;
break;
}
catch (Exception e)
{
if (i == 5 - 1)
{
throw e;
}
else
{
DLog.Warn("Failed to upload file. Retry #" + (i + 1) + ": " + path);
Thread.Sleep(1000);
}
}
}
}
The problem is these function have different signature so I can not pass them as parameter using delegate. Is there a way or pattern can help me solve this problem?
CheckFunctionWithTrialsmethod?