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

4

1 回答 1

0

检查以确保正在创建和“抛出”事件。

于 2012-05-24T20:42:00.317 回答