0

J'ai un rapport qui prend environ 2 ou 3 minutes pour tirer toutes les donnéeslong processus en cours d'exécution en utilisant Asp.net page asynch

Je suis en train d'utiliser des pages ASP.net ASYNCH pour éviter un délai d'attente. Mais ne peut pas faire fonctionner

est ici ce que je fais:

private delegate List<PublishedPagesDataItem> AsyncReportDataDelegate(); 

private AsyncReportDataDelegate longRunningMethod; 

private List<PublishedPagesDataItem> reportData; 

public PublishedPagesReport() // this is the constructor 
{ 
    reportData = new List<PublishedPagesDataItem>(); 
    longRunningMethod = GetReportData; 
} 


protected void Page_Load(object sender, EventArgs e) 
{ 
    this.PreRenderComplete += 
     new EventHandler(Page_PreRenderComplete); 

    AddOnPreRenderCompleteAsync(
     new BeginEventHandler(BeginAsynchOperation), 
     new EndEventHandler(EndAsynchOperation) 
    ); 
} 

private List<PublishedPagesDataItem> GetReportData() 
{ 
    // this is a long running method 
} 

private IAsyncResult BeginAsynchOperation(object sender, EventArgs e, AsyncCallback cb, object extradata) 
{ 
    return longRunningMethod.BeginInvoke(cb, extradata); 
} 

private void EndAsynchOperation(IAsyncResult ar) 
{ 
    reportData = longRunningMethod.EndInvoke(ar); 
} 

private void Page_PreRenderComplete(object sender, EventArgs e) 
{ 
    reportGridView.DataSource = reportData; 
    reportGridView.DataBind(); 
} 

J'ai donc un délégué représentant la méthode longue course (GetReportData).

Et je suis en train de l'appeler comme par cet article:

http://msdn.microsoft.com/en-us/magazine/cc163725.aspx

La longue méthode de fonctionnement ne complète dans le débogueur, mais des points d'arrêt sur le EndAsynchOperation et les méthodes Page_PreRenderComplete ne Touchés

tout idée de ce que je fais mal?

Répondre

0

le code ci-dessous fonctionne. pas sûr de ce que la différence est, sauf qu'il ya un if (!IsPostBack)

De toute façon, maintenant résolu

private delegate List<PublishedPagesDataItem> AsyncReportDataDelegate(); 

private AsyncReportDataDelegate longRunningMethod; 

private List<PublishedPagesDataItem> reportData; 

public asynchtest() 
{ 
    reportData = new List<PublishedPagesDataItem>(); 
    longRunningMethod = GetReportData; 
} 

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     // Hook PreRenderComplete event for data binding 
     this.PreRenderComplete += 
      new EventHandler(Page_PreRenderComplete); 

     // Register async methods 
     AddOnPreRenderCompleteAsync(
      new BeginEventHandler(BeginAsyncOperation), 
      new EndEventHandler(EndAsyncOperation) 
     ); 
    } 
} 
IAsyncResult BeginAsyncOperation(object sender, EventArgs e, 
    AsyncCallback cb, object state) 
{ 
    return longRunningMethod.BeginInvoke(cb, state); 
} 

void EndAsyncOperation(IAsyncResult ar) 
{ 
    reportData = longRunningMethod.EndInvoke(ar); 
} 

protected void Page_PreRenderComplete(object sender, EventArgs e) 
{ 
    Output.DataSource = reportData; 
    Output.DataBind(); 
}