Tuesday, June 28, 2005 1:21 AM
DmitryR
Deadlocks in async ASP.NET pages (part 2)
Another common mistake is to ‘forget’ to pass AsyncCallback delegate to the begin method. It is relatively easy to 'forget' because there are overloads of some 'begin' methods that don’t take AsyncCallback parameter. In the following example a wrong overload of SqlCommend.BeginExecuteReader is used:
IAsyncResult BeginGetAsyncData(Object src, EventArgs args,
AsyncCallback cb, Object state) {
_myCommand = new SqlCommand(…);
return _myCommand.BeginExecuteReader();
}
The page above will never complete. The right way to pass the delegate to the async component:
IAsyncResult BeginGetAsyncData(Object src, EventArgs args,
AsyncCallback cb, Object state) {
_myCommand = new SqlCommand(…);
return _myCommand.BeginExecuteReader(cb, state);
}