English 中文(简体)
助老板
原标题:help with c# timer
  • 时间:2011-08-16 15:31:30
  •  标签:
  • c#
  • timer

i) 具备这个时间。

public class HomeController : Controller
{
    public int count = 0;
    public ActionResult Index()
    {
        Timer timer = new Timer();
        timer.Interval = 1000;
        timer.Elapsed += new ElapsedEventHandler(onTimer);
        timer.Start();
        return View();
    }
    public void onTimer(Object source, ElapsedEventArgs e)
    {
        count++;
    }  
    [HttpPost]
    public JsonResult CheckStatus()
    {
        return Json(count);
    }

我认为:

<script type="text/javascript">
$(function () {
    // poll every 5 seconds
    setInterval( checkStatus() , 3000);
});

function checkStatus() {
    $.ajax({
        url:  Home/CheckStatus ,
        type:  POST ,
        dataType:  json ,
        success: function (xhr_data) {
            document.getElementById("test").innerText = xhr_data;
        }
    });
}

为什么它只向我(当跑时)展示吗? 为什么没有我:0,1,2等?

最佳回答

每当你提出要求时,将设立一个新的控制员小组。 因此,你一再发出的美国宇宙航空研究开发机构呼吁仅仅收到0份,因为这一条标码的“<>面值/代码>价值已初步确定。

There will likely be other controllers (with timers running) floating around until the GC runs to collect them, but they will have no effect on the new controller that is actually processing each individual request.

我不知道你试图通过这一守则解决哪些问题,但你是否调查了<条码>日码<>和<条码>。 他们提供客户服务,可能适合你的工作。

如果你需要持续的服务器边数据,那么就有一些备选办法,包括:

如果是,哪些是正确的,取决于你重新努力解决的实际问题。

问题回答

由于您的时.在一页的生命周期内,假定是伙伴关系。 NET。 每当出现倒退时,都会有新的情况。

我不敢肯定如何获得工作的时间,但为了克服各种挫折,你使用像观察国、会议或Cache这样的东西。

是否要求控制员在每次提出请求时即时进行,因此每当你提出要求时,价值将是零?

If you want a global counter, use Application or a static field. If you want it to count per user use session.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签