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
我把你的代碼放到一個新的項目中,它對我很有用。你有一個完整的repro? –
你怎麼知道它「從雲端讀取」? –