简体   繁体   English

等待异步获得价值Windows Phone 7

[英]Waiting until async gets value Windows Phone 7

I have problem with logging operation in WP7. 我在WP7中记录操作有问题。 When I click LogInButton it doesn't gets value to prompt = e.Result in proxy. 当我单击LogInButton时,没有值提示= e.Result在代理中。 What can I do to wait until async call is ended? 等待异步呼叫结束该怎么办? I though about Thread. 我虽然关于线程。 Sleep but i suppose it isn't able to do in WP 7. 睡觉,但我想它在WP 7中无法完成。

namespace WP7App
{
 public partial class MainPage : PhoneApplicationPage
{
    bool prompt;
    // Constructor
    public MainPage()
    {
        InitializeComponent();
    }
    // login operation
    private void Log(string username, string passwd)
    {
        Service1Client proxy = new Service1Client();
        proxy.LogInCompleted += new
        EventHandler<LogInCompletedEventArgs>(proxy_LogInCompleted);
        proxy.LogInAsync(username, passwd);

    }
    public void proxy_LogInCompleted(object sender, LogInCompletedEventArgs e)
    {
        prompt = e.Result;              
    }
    //button action
    void LogInButton_Click(object sender, RoutedEventArgs e)
    {
        if (LoginBox.Text == null) { MessageBox.Show("please fill login box"); }
        if (PasswdBox.Password == null) { MessageBox.Show("enter your password"); }
        string login = LoginBox.Text;
        string passwd = PasswdBox.Password;            
        Log(login, passwd);
        if (prompt == true)
        {
            NavigationService.Navigate(new Uri("/Pages/MainLogged.xaml", UriKind.Relative));
        }
        else
        {
            MessageBox.Show("logging failed");
        }
    }                            
}

} }

The only thing you should do is just provide user information, that some operation is still running. 您唯一要做的就是仅提供用户信息,表明某些操作仍在运行。

If you really need that (the operation result is necessary for application) it can be done in a way, that blocks user from making another operations (like a fullscreen panel which should be shown just before starting async operation and closed when it's completed). 如果确实需要(操作结果对于应用程序来说是必需的),则可以通过某种方式来完成操作,从而阻止用户进行其他操作(例如全屏面板,应在启动异步操作之前显示该面板,并在完成异步操作后关闭它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM