
1.先创建一个WCf的应用程序
2.在窗体里调用的步骤
2.1添加接口
//异步调用
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
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);
}
评价
排名
4
文章
473
粉丝
3
评论
2
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术