1

I have a question about a scenario I need to code. I have a process that will send a request file via SFTP and then I will need to wait for a response file to be created on the ftp server before I download and continue my processing. The response file could take anywhere between 1min to 60mins to appear. If I await this process, is there a way that I can say, give up after 60 mins? C#

Terry
  • 23
  • 6

1 Answers1

1

Use a CancellationTokenSource

private CancellationTokenSource _cancellationTokenSource =
    new CancellationTokenSource(TimeSpan.FromMinutes(60));

Wrap the code in a try/catch and watch for TaskCanceledException

Also, check out Asynchronously wait for Task to complete with timeout

Karen Payne
  • 4,341
  • 2
  • 14
  • 31