退出方法后不执行查询
Query not executing after exiting method
我有一个来自我编写的 Web 服务的简单插入查询 运行。单击按钮时,我有一个 运行 调用 Web 服务并执行插入查询的方法。出于某种原因,在我退出单击事件之前,它实际上并没有插入信息……谁能告诉我为什么?我将post代码如下:
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
//inserts new article into DB
Insert();
}
private void InsertNewArticle()
{
ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
ArticleDetails articleInfo = new ArticleDetails();
articleInfo.Title = newsTitle;
articleInfo.Body = newsBody;
articleInfo.Author = newsAuthor;
service.InsertArticleDetailsAsync(articleInfo);
}
我通过调试它看到的是,它在退出 btnSubmit_Click
事件之前不会执行。这对我来说是个问题的原因是我想对退出点击事件之前刚刚提交的信息做一些事情。
注意:这是一个通用Windows应用程序
您正在调用一个异步方法,但没有等待它执行。将 InsertNewArticle 方法更改为
private async void InsertNewArticle()
{
ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
ArticleDetails articleInfo = new ArticleDetails();
articleInfo.Title = newsTitle;
articleInfo.Body = newsBody;
articleInfo.Author = newsAuthor;
await service.InsertArticleDetailsAsync(articleInfo);
}
我有一个来自我编写的 Web 服务的简单插入查询 运行。单击按钮时,我有一个 运行 调用 Web 服务并执行插入查询的方法。出于某种原因,在我退出单击事件之前,它实际上并没有插入信息……谁能告诉我为什么?我将post代码如下:
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
//inserts new article into DB
Insert();
}
private void InsertNewArticle()
{
ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
ArticleDetails articleInfo = new ArticleDetails();
articleInfo.Title = newsTitle;
articleInfo.Body = newsBody;
articleInfo.Author = newsAuthor;
service.InsertArticleDetailsAsync(articleInfo);
}
我通过调试它看到的是,它在退出 btnSubmit_Click
事件之前不会执行。这对我来说是个问题的原因是我想对退出点击事件之前刚刚提交的信息做一些事情。
注意:这是一个通用Windows应用程序
您正在调用一个异步方法,但没有等待它执行。将 InsertNewArticle 方法更改为
private async void InsertNewArticle()
{
ServiceReference1.Service1Client service = new ServiceReference1.Service1Client();
ArticleDetails articleInfo = new ArticleDetails();
articleInfo.Title = newsTitle;
articleInfo.Body = newsBody;
articleInfo.Author = newsAuthor;
await service.InsertArticleDetailsAsync(articleInfo);
}