I would like to issue a SQL Server query (task1) and do some kind of monitoring in a loop (task2) while waiting for the query result. When task2 finds a certain condition is met, the query needs to be cancelled (I will use SQLCommand.Cancel()). This means either task2 can issue the cancel command, or signals task1 to cancel it. Either when the result is returned or the cancel happens, task2 ends and task1 continues executing to the end of the method.
What's an optimal and simple construct to use for this? TPL, Async/await, waithandles, events..? Using .NET 4.5 in a class (not UI).