2012-05-24 153 views
1

我在WP-7应用程序中遇到问题。 我有一个事件,当我从云端读取 - OpenReadCompletedEventHandler, ,但不知何故事件发生时,无法执行EventHandler。无法执行事件处理程序

这里是我的功能:

public void SetCategories() 
    //set the Companies table from Shret.net DataBase 
    { 
     try 
     { 
      WebClient webClient = new WebClient(); 
      Uri uri = new Uri("http://api.sherut.net/?method=Category"); 
      webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted); 

      try 
      { 
       webClient.OpenReadAsync(uri); 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
    } 
    void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
    { 
     DataContractJsonSerializer serializer = null; 
     try 
     { 
      serializer = new DataContractJsonSerializer(typeof(Categories)); 
      var categories = (Categories)serializer.ReadObject(e.Result); 
      // foreach (Company c in companies.data) 

      // MessageBox.Show(c.Name + " " + c.CompanyID+" "+c.CompanyGUID); 
      //לכתוב לבסיס נתונים באפליקציה 
      BuildCategoriesDB(); //build the local data base 
      AddCategoriesData(categories); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
    } 

它从云端读取,但它并没有去处理程序中:webClient_OpenReadCompleted

+0

我把你的代码放到一个新的项目中,它对我很有用。你有一个完整的repro? –

+0

你怎么知道它“从云端读取”? –

回答

0

检查以确保正在创建活动和“甩” 。

相关问题