我的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 :(得分:0)
检查以确保正在创建事件并“抛出”。