代码之家  ›  专栏  ›  技术社区  ›  Shrewdroid

Silverlight 4异步问题

  •  1
  • Shrewdroid  · 技术社区  · 15 年前

    我正在Silverlight 4中创建一个应用程序。用户接触的第一个屏幕是登录屏幕(Login.xaml)。我已经在Login.xaml.cs文件中编写了以下代码。

    private void btnSubmit_Click(object sender, RoutedEventArgs e)
    {
        //first validate if the user is authorised for this application
        if (this.ValidateEntry())
        {
            if (UserAuthenticationBL.AuthenticateUser(txtUserName.Text.Trim(), txtPassword.Password.Trim()))
            {
                //since the user is authenticated we will show the dashboard screen
                this.Content = new MainPage();
            }
            else
            {
                this.ShowErrorMessage("Invalid username or password");
                txtUserName.Focus();
            }
        }
    }
    

    我的问题是在获取AuthenticateUser方法中的数据之前执行代码。代码会立即变为“无效的用户名或密码”,并在完成对xaml页面的所有执行之后加载列表。

    我知道异步thingi有问题……我还知道我需要放置一个事件来知道加载何时完成。。。。。。。。

    但我不知道该怎么办!!! 有人能帮我解释一下这个问题吗。。。

    谢谢您。

    1 回复  |  直到 14 年前
        1
  •  0
  •   JSBach    15 年前

    如果我理解正确,那么AuthenticateUser方法正在运行async,对吧?

    只有一个问题,如果您的行为应该是同步的,为什么要异步执行?(在决定做什么之前你必须得到答案)。

    http://msdn.microsoft.com/en-us/library/aa719598%28VS.71%29.aspx 可能有帮助:)

    推荐文章