我在 WP7 中的日志记录操作有问题。当我单击 LogInButton 时,它没有在代理中提示 = e.Result 的值。我该怎么做才能等到异步调用结束?我虽然关于线程。睡眠,但我想它在 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");
}
}
}
}