[英]How to run two functions simultaneously without pausing each other in asp net mvc
I am using an SMS web service panel
. 我正在使用
SMS web service panel
。 In controller action HttpPost
I call a method for sending SMS. 在
controller action HttpPost
我调用了一种发送SMS的方法。 I want to run this function simultaneously but I don't want to use async thread
. 我想同时运行此函数,但我不想使用
async thread
。 Because first method is paused . 因为第一种方法已暂停 。 Sending SMS is not important and if it failed to connect SMS web service I don't want to paused main action.
发送SMS并不重要,如果连接SMS Web服务失败,则我不想暂停主要操作。 How can I run these two methods simultaneously?
如何同时运行这两种方法?
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult ServicesRes(FormCollection collection)
{
.
.
.
sendSMS();
....
return Json(result, JsonRequestBehavior.AllowGet);
}
[UPDATE] [UPDATE]
I tried async but not work 我尝试异步但不起作用
Main Action: 主要动作:
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult ServicesRes(FormCollection collection)
{
.
.
.
await sendSMS();
....
return Json(result, JsonRequestBehavior.AllowGet);
}
//Send SMS //发简讯
private async Task sendSMS()
{
...
await Task.FromResult(0);
}
You need to use kind of Asynchronous programming here, for example this code run a thread without blocking current execution. 您需要在此处使用某种异步编程,例如,此代码在不阻止当前执行的情况下运行线程。
System.Threading.Tasks.Task task = new Task(()=>
{
sendSMS();
});
task.Start();
In c# you can also make your sendSMS async. 在c#中,您还可以使sendSMS异步。 for example like this
例如这样
public async Task sendSMS()
{
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.