在ActionResult和工作线程之间进行通信

时间:2016-08-17 15:12:02

标签: c# .net multithreading

我有一个动作(StartJob),它启动一个长时间运行的工作线程。我正在尝试另一个操作(GetStatusFromWrokerThread)返回LongRunningJob进程的当前状态。这可能吗?

    public ActionResult StartJob(int[] instList)
    {
        permissionCheck = new Thread(LongRunningJob);
        permissionCheck.Start();

        var jr = new JsonNetResult();
        jr.Formatting = Newtonsoft.Json.Formatting.Indented;
        jr.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
        jr.Data = (inQueue <= 0?0:inQueue);

        return jr;
    }


    public ActionResult GetStatusFromWrokerThread()
    {
        // how to get a status code or message from LongRunningJob 
        // the thread started in the action above


        var jr = new JsonNetResult();
        jr.Formatting = Newtonsoft.Json.Formatting.Indented;
        jr.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
        jr.Data = (inQueue <= 0 ? 0 : inQueue);

        return jr;
    }

0 个答案:

没有答案