发射后不管(非同步)ASP.NET方法调用 [英] Fire and Forget (Asynch) ASP.NET Method Call

查看:118
本文介绍了发射后不管(非同步)ASP.NET方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个服务以更新客户信息到服务器。一个服务调用需要几秒钟左右,这是正常的。

We have a service to update customer information to server. One service call takes around few seconds, which is normal.

现在我们有一个新的页面,在一个实例35-50左右信息的costumers可以更新。改变服务接口来接受所有客户在一起是毫无疑问的在这一点上。

Now we have a new page where at one instance around 35-50 Costumers information can be updated. Changing service interface to accept all customers together is out of question at this point.

我需要调用一个方法(说ProcessCustomerInfo),这将通过客户的信息和循环调用Web服务的35-50倍。调用服务异步是没有多大用处。

I need to call a method (say "ProcessCustomerInfo"), which will loop through customers information and call web service 35-50 times. Calling service asynchronously is not of much use.

我需要调用方法ProcessCustomerInfo异步。我想使用的 RegisterAsyncTask 的这一点。有在网上提供各种实例,但问题是发起这次通话后,如果我从这个页面搬走,处理停止。

I need to call the method "ProcessCustomerInfo" asynchronously. I am trying to use RegisterAsyncTask for this. There are various examples available on web, but the problem is after initiating this call if I move away from this page, the processing stops.

是否有可能实现的消防和忘记的方法调用,这样用户可以移动远离页面(重定向到另一页)不停止方法处理?

Is it possible to implement Fire and Forget method call so that user can move away (Redirect to another page) from the page without stopping method processing?

推荐答案

上的详细信息:<一href=\"http://www.$c$cproject.com/KB/cs/AsyncMethodInvocation.aspx\">http://www.$c$cproject.com/KB/cs/AsyncMethodInvocation.aspx

基本上,你可以创建一个指向要异步运行,然后用BeginInvoke来踢它关闭的方法的委托。

Basically you can create a delegate which points to the method you want to run asynchronously and then kick it off with BeginInvoke.

// Declare the delegate - name it whatever you would like
public delegate void ProcessCustomerInfoDelegate();

// Instantiate the delegate and kick it off with BeginInvoke
ProcessCustomerInfoDelegate d = new ProcessCustomerInfoDelegate(ProcessCustomerInfo); 
simpleDelegate.BeginInvoke(null, null);

// The method which will run Asynchronously
void ProcessCustomerInfo()
{
   // this is where you can call your webservice 50 times
}

这篇关于发射后不管(非同步)ASP.NET方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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