I have a stored procedure, which writes a backup of a specific database. I call this SP in a C# / Windows Forms application asynchrounously. Here is the code snipped:
IAsyncResult result = command.BeginExecuteNonQuery();
while (!result.IsCompleted)
{
System.Threading.Thread.Sleep(1000);
...
}
command.EndExecuteNonQuery(result));
After some time the program leaves the loop, because IsCompleted = true and calls EndExecuteNonQuery. The problem now is, that the Job is still busy and EndExecuteNonQuery is blocked! This causes a server timeout after some minutes. It seems that the IsCompleted value is not consistent respectively what's wrong with IsCompleted? How can I achieve that my program recognizes the "real job status"?