ASP.net PageAsyncTaks - 如何参数传递到任务吗? [英] ASP.net PageAsyncTaks - how to pass parameter to the task?

查看:86
本文介绍了ASP.net PageAsyncTaks - 如何参数传递到任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待作出一系列的Web服务调用(所有相同的服务,不同的paramters每一次传递)。

我已经做了一点阅读PageAsyncTasks,他们看的权利,但不知道如何往下传递参数给每个呼叫的服务。下面大大简化的例子 - 真实世界将围绕循环并注册每个任务要执行之前,改变参数:

 保护覆盖无效的OnInit(EventArgs的发送)
{
    base.OnInit(E);
    INT myParameter = 1;    VAR任务=新PageAsyncTask(的BeginRequest,EndRequest,NULL,NULL,TRUE);
    RegisterAsyncTask(任务);
}IAsyncResult的的BeginRequest(对象发件人,EventArgs的发送,CB的AsyncCallback,对象状态)
{
    VAR的服务=新ServiceClient();    返回service.BeginServiceCall(小于如何获取参数的异步调用>中?
                CB,服务);
}...结束请求等....


解决方案

的第四个参数(国家在我们的例子)可用于在一个对象作为参数传递给你的任务。如果您有需要传递一个以上的参数,你要创建一个容纳所有这些参数,将你的任务中使用一个单独的类(DataTransferObject为例)。

I'm looking to make a series of web service calls (all to the same service, different paramters passed each time).

I've been doing a bit of reading about PageAsyncTasks, and they look right, but not sure how to pass a parameter down to each call to the service. Much simplified example below - real world will be looping around and changing the parameter before registering each task to be performed:

protected override void OnInit(EventArgs e)
{    
    base.OnInit(e);     
    int myParameter = 1;

    var task = new PageAsyncTask(BeginRequest, EndRequest, null, null, true);
    RegisterAsyncTask(task);    
} 

IAsyncResult BeginRequest(Object sender, EventArgs e, AsyncCallback cb, object state)
{    
    var service = new ServiceClient();    

    return service.BeginServiceCall(<How to get the parameter to the async call?>, 
                cb, service);
} 

... End request etc....

解决方案

The 4th argument ("state" in our example) can be used to pass in an object as a parameter to your task. If you have more than one parameter that needs to be passed in, you'll want to create a seperate class (a DataTransferObject for example) that hold all of these parameters that would be used by your task.

这篇关于ASP.net PageAsyncTaks - 如何参数传递到任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆