I have a WPF application with a Linq to SQL model. In the .dbml file, I have a stored procedure that returns the coordinates of an address. The procedure use the active internet conection to call a google maps “service” and get the coordinates.
The problem is, when the internet conection is slow, or is busy, the procedure takes long time to return the coordinates and I get a TimeOut exception in C#.
I was wondering if is there a way to control If the procedure takes more than x seconds to return, then skip it and continues with the process because the coordinates is not a mandatory information.
Thanks!
The only way you could do this is to run the SP asynchronously and with a timer, cancel the async process when X seconds have passed.
To accomplish this you could take the easy way and use a
Task.Next, you can create a
CancellationTokenand pass it to the task’s start method. When the timer times out (your timer, not the SP), just cancel the task. For a quick way on how to do this I’m going to ask you to read the answer on this question.