2

我根据 XNA GamerService 对话框询问我的应用程序用户,他是否真的想删除特定产品。

如果他按下是,这将采取行动:

private void OnMessageBoxAction(IAsyncResult ar)
        {
            int? selectedButton = Guide.EndShowMessageBox(ar);
            switch (selectedButton)
            {
                case 0:
                    WebClient cweight = new WebClient();
                    cweight.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");

                    cweight.Credentials = new NetworkCredential(op.username, op.userpass);
                    cweight.DownloadStringCompleted += new DownloadStringCompletedEventHandler(deleted);
                    cweight.DownloadStringAsync(new Uri("http://mydomain.com"));
                    break;

                case 1:
                    Debug.WriteLine("1 pressed");
                    break;

                default:
                    Debug.WriteLine("default pressed");
                    break;
            }
        }

下载完成后,我调用登录方法:

private void deleted(object sender, DownloadStringCompletedEventArgs e)
        {
            Debug.WriteLine("\n[#] deleted");

            if (e.Error != null)
            {
                Debug.WriteLine("Delete problem");
            }

            Debug.WriteLine("Delete successful");
            login(null, null);
        }

后来在login我得到了无效的跨线程访问,globalprogress.Visibility = System.Windows.Visibility.Visible;我很确定,这个错误会通过整个登录方法发生。

4

1 回答 1

0

实用类:

public class SmartDispatcher
{
    public static void BeginInvoke(Action action)
    {
        if (Deployment.Current.Dispatcher.CheckAccess()
            || DesignerProperties.IsInDesignTool)
        {
            action();
        }
        else
        {
            Deployment.Current.Dispatcher.BeginInvoke(action);
        }
    }
}
于 2012-11-03T16:49:23.510 回答