'Async long running process

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#



Solution 1:[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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1