웹 양식 vs2010 fw4와 함께 PageAsyncTask
을 사용하는 이전 프로젝트를 지원해야합니다.응답이 PageAsyncTask로 끝나지 않습니까?
그러나이 간단한 코드는 컴파일 + 실행 (디버그 모드/추적 모드에서는 오류 없음)이지만 응답이 끝나지 않습니다.
디버그 모드 + 브레이크 포인트를 보면 코드의 모든 단계에 도달합니다.
public partial class _Default2 : System.Web.UI.Page
{
IAsyncResult BeginGetData(object sender, EventArgs e, AsyncCallback callback, object state)
{
SqlConnection con = new SqlConnection(@"Data Source=... Asynchronous Processing=True;");
var sql = @" SELECT [NAME] FROM [WebERP].[dbo].[t]";
{
SqlCommand _cmd = null;
try
{
_cmd = new SqlCommand(sql, con);
_cmd.CommandTimeout = 100000;
con.Open();
return _cmd.BeginExecuteReader(EndGetData, _cmd);
}
catch (Exception ex)
{
if (_cmd != null) _cmd.Dispose();
con.Close();
throw;
}
}
}
void EndGetData(IAsyncResult ar)
{
(ar.AsyncState as SqlCommand).EndExecuteReader(ar);
Response.Write(1111); // HttpContext.Current.Response also doesnt help
}
void TimeoutData(IAsyncResult ar)
{
Response.Write("Could not retrieve data!");
}
protected void Page_Load(object sender, EventArgs e)
{
PageAsyncTask task = new PageAsyncTask(BeginGetData, EndGetData, TimeoutData, null, true);
Page.RegisterAsyncTask(task);
Page.ExecuteRegisteredAsyncTasks();
}
}
질문
응답은 끝나지 않아. 내가 보는 모든이다 : 나는 무엇을 놓치고
?
는 - 내가 여기에 문제가 당신이 BeginExecuteReader
및 new PageAsyncTask()
모두 같은 BeginGetData
및 EndGetData
콜백을 통과한다는 생각
나는'BeginExecuteReader'와'PageAsyncTask'에 같은'EndGetData'를 넘겨 주어야한다고 생각하지 않습니다. – Noseratio
@Noseratio ouch .... 감사합니다. 아마도 그걸 놓쳤을거야. 올바른 행은'IAsyncResult BeginGetData (객체 발신자, EventArgs e, AsyncCallback 콜백, 객체 상태)에서 콜백이 선언 된 return _cmd.BeginExecuteReader (콜백 (!!!!), 상태) '이어야합니다. –