如何在MVC4中使用C#Timer运行后台进程 [英] How To Run a Background Process using C# Timer in MVC4

查看:244
本文介绍了如何在MVC4中使用C#Timer运行后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ .ajax({

类型:POST,

url:BackGroundService / DispatcherTimerSetup,

数据:{lati :lati,longi:longi},

async:true,

cache:false,

数据类型:html,



[HttpPost]

public void DispatcherTimerSetup(HttpClient httpClient,string lati,string longi,string UserId)

{

dispatcherTimer = new DispatcherTimer();

dispatcherTimer.Tick + = dispatcherTimer_Tick;

dispatcherTimer.Interval = new TimeSpan(0,0,2);

if(!dispatcherTimer.IsEnabled)

{

dispatcherTimer.Start();

}

}

async void dispatcherTimer_Tick(对象发送者,对象e)

{

//某些功能

}



我试过Dispacher但它不起作用意味着Break Point没有击中dispatcherTimer_Tick(对象发送者,对象e)这种方法所以我决定用Normal Timer做它自我可以任何人给我任何例子请

$.ajax({
type: "POST",
url: "BackGroundService/DispatcherTimerSetup",
data: { lati: lati, longi: longi },
async: true,
cache: false,
datatype: "html",

[HttpPost]
public void DispatcherTimerSetup(HttpClient httpClient, string lati, string longi, string UserId)
{
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 2);
if (!dispatcherTimer.IsEnabled)
{
dispatcherTimer.Start();
}
}
async void dispatcherTimer_Tick(object sender, object e)
{
//Some functionality
}

I tried Dispacher But it's not working means Break Point not hitting dispatcherTimer_Tick(object sender, object e) this method So I decided to do with Normal Timer it self can any one give me any Examples please

推荐答案

为什么在Web应用程序的服务器端使用Timer?它没有任何意义,因为Web服务器永远不能调用客户端。它有什么用?



背景过程究竟是什么意思?这个过程应该做什么?
Why are you using a Timer in the server side of a web app? It doesn't make any sense since the web server can never call the client. What use is it?

What exactly do you mean by "background process"?? What is this process supposed to do?


这篇关于如何在MVC4中使用C#Timer运行后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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