我在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
发布于 2012-05-25 04:42:00
检查以确保事件正在被创建和“抛出”。
https://stackoverflow.com/questions/10743655
复制相似问题