首页
视频
资源
登录
原
接口异步调用
4188
人阅读
2021/4/25 11:50
总访问:
1054488
评论:
0
收藏:
0
手机
分类:
mvc
## 1.先创建一个WCf的应用程序 ## 2.在窗体里调用的步骤 2.1添加接口![](https://img.tnblog.net/arcimg/18328907536/d6ee4685bfab49e1a33f16ea127dad36.png) //异步调用 private void button1_Click(object sender, EventArgs e) {//方法一:自己开辟线程 ### //1.1用Thread开辟线程是比较老的方法 Thread thread = new Thread(() => { Service2.Service2Client client = new Service2.Service2Client(); int result = client.Sum(1, 3); MessageBox.Show(result + ""); }); thread.Start(); } ### //方法1.2 private void button1_Click(object sender, EventArgs e) { //1.2使用task开辟 Task.Run(() => { Service2.Service2Client client = new Service2.Service2Client(); int result = client.Sum(1, 3); MessageBox.Show(result + ""); }); } ###//方法2 private void button1_Click(object sender, EventArgs e) { CallSumAsyuc(); } #### 方法2"方法CallSumAsyuc()"的位置 public async void CallSumAsyuc() { Service2.Service2Client client = new Service2.Service2Client(); int result = await client.SumAsync(1, 3); MessageBox.Show(result + ""); } ### //方法3 ![](https://img.tnblog.net/arcimg/18328907536/56158f6601594df1bf1daf52acc2af11.png) private void button1_Click(object sender, EventArgs e) { //首先在 Service2右击“配置服务应用”=>"点生成异步操作" Service2.Service2Client client = new Service2.Service2Client(); client.SumAsync(6,6); //接口方法执行完毕后执行 client.SumCompleted += client_SumCompleted; } ####方法client.SumCompleted += client_SumCompleted处 public void client_SumCompleted(object sender, Service2.SumCompletedEventArgs e) { MessageBox.Show("接口返回值:"+e.Result); }
👈{{preArticle.title}}
👉{{nextArticle.title}}
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}
除暖
没有个性,不需要签名
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
mvc
9篇
vue
4篇
ABP
34篇
Linq
1篇
Java
41篇
Mybatis
15篇
Mybatis高
13篇
spring boot
9篇
spingboot高
11篇
Tomcat
10篇
Http
3篇
Java Web
4篇
Servlet
14篇
servlet 3.1
2篇
JaWeb请求
9篇
更多
JaWeb响应
9篇
JavaCookie
3篇
JavaSession
2篇
权限管理
3篇
待学习
3篇
AOP
0篇
Github
16篇
项目1
3篇
JS
1篇
Filter
7篇
监听器
2篇
JDBC
7篇
Redis
2篇
Maven
15篇
正则
4篇
SQL Server
3篇
Mysql
8篇
mybatis_plus
2篇
SpringCloud
0篇
ASP.NET
10篇
K8s
1篇
Linux
40篇
Windows
2篇
JavaEE
28篇
Java集合
26篇
spring
46篇
SpringMVC
35篇
jQuery
1篇
Dubbo
8篇
随笔
7篇
最新文章
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2024
TNBLOG.NET
技术交流:
群号656732739
联系我们:
contact@tnblog.net
欢迎加群
欢迎加群交流技术