private void HandleCallback(IAsyncResult result) { try { // Retrieve the original command object, passed to this procedure in the AsyncState property // of the IAsyncResult parameter. SqlCommand command = (SqlCommand)result.AsyncState; SqlDataReader dr = command.EndExecuteReader(result); // To execute the code from a different thread instead of main thread. DelFillGrid del = new DelFillGrid(FillGrid); // To call the form's delegate. this.Invoke(del, dr); // Reader is to be closed at the end, as some thread may be using it. Use seperate procedure to close it } catch (Exception ex) { // We are running the code in a seperate thread so we need to catch the exception. // Else we are unable to catch the exception anywhere. this.Invoke(new DisplayStatusDelegate(DisplayStatus), "Error: " + ex.Message); } finally { isExecuting = false; if (conn != null) { conn.Close(); } } }
private void HandleCallback(IAsyncResult result) { try { // Retrieve the original command object, passed to this procedure in the AsyncState property // of the IAsyncResult parameter. SqlCommand command = (SqlCommand)result.AsyncState; SqlDataReader dr = command.EndExecuteReader(result); // To execute the code from a different thread instead of main thread. DelFillGrid del = new DelFillGrid(FillGrid); // To call the form's delegate. this.Invoke(del, dr); // Reader is to be closed at the end, as some thread may be using it. Use seperate procedure to close it } catch (Exception ex) { // We are running the code in a seperate thread so we need to catch the exception. // Else we are unable to catch the exception anywhere. this.Invoke(new DisplayStatusDelegate(DisplayStatus), "Error: " + ex.Message); } finally { isExecuting = false; if (conn != null) { conn.Close(); } } }