2011-06-06 29 views
4

我有一個updatepanel,它包含一個頁面完成加載後的下拉菜單,它將使用最新的數據填充下拉菜單。數據抓取可能需要3分鐘。我可以選擇讓用戶「取消」請求並只使用最新版本的數據嗎?我可以「取消」一個在updatepanel內發生的長時間運行的進程嗎?

在updatepanel中,我有一個未綁定的下拉列表(在設計時)。一旦頁面完成渲染,我JavaScript調用在UpdatePanel內的button.click事件獲取數據:

private void RefreshDDL() 
{ 
    hidAction.Value = ""; 
    ddlCampaigns.DataSource = myDataSource; 
    ddlCampaigns.DataTextField = "Value"; 
    ddlCampaigns.DataValueField = "Key"; 
    ddlCampaigns.DataBind(); 
    ddlCampaigns.Visible = true; 

    pnlDetails.Attributes.CssStyle.Clear(); 
    pnlPleaseWait.Visible = false; 
    btnOK.Enabled = true; 
} 

對象「myDataSource」是我創建的繼承IEnumarable並具有一個裸露public List<DictionaryEntry>的對象,是「關鍵」和「價值」發揮作用的地方。

當構造函數被調用時,它會轉到web服務並獲取我想要用於下拉菜單的數據。這個獲取需要將近3分鐘才能完成,然後將其存儲到我的數據庫中。然後我拿起數據庫表並填充public List<DictionaryEntry>,然後它返回到updatepanel供消費。

體系結構爲獲取(第三方)工作的方式是我爲數據對象發出請求(通過web服務)。它立即返回結果的唯一標識符。然後我使用服務中的另一種方法並傳入唯一標識來檢查數據的狀態。我循環每10秒檢查一次。一旦它返回一個「完整」的消息時,我使用相同的唯一ID獲取的實際數據:

private void RefreshList() 
{ 
    MyProxy proxyRequest = new MyProxy(); 
    List<string> myList= new List<string>(); 
    if (UpdateNeeded()) 
    { 
     ProgramManagement.ThirdPartyServiceApi.runReport report = new ProgramManagement.ThirdPartyServiceApi.runReport(); 
     report.reportName = "MyData"; 
     try 
     { 
      ProgramManagement.ThirdPartyServiceApi.runReportResponse response = proxyRequest.runReport(report); 

      while (!ReportComplete([email protected])) 
      { 
       System.Threading.Thread.Sleep(10000); 
      } 
      StoreList(GetReport([email protected])); 
     } 
     catch (SoapException ex) 
     { 
      if (ex.Message == TOO_MANY_REQUESTS) 
      { 
       //display a message maybe? 
      } 
     } 
    } 

    AddDataToList(); 

} 

有沒有什麼辦法阻止這個過程中流?我想我會在while循環中放置一個cog來停止它。

感謝您的閱讀。

+0

只刪除了你的問題,你可以取消同步回發:http://www.dotnetcurry.com/ShowArticle.aspx?ID = 176 – 2011-06-06 13:36:50

回答

0

您可以添加UpdateProgress您的頁面,裏面的ProgressTemplate把 ,這將取消回傳,您將有機會處理代碼中的取消。 你也應該從其他答案中添加代碼來取消回發。

相關問題