Exemplo n.º 1
0
 int PostTimerTask(TaskNode taskNode, int delay)
 {
     taskNode.delay     = delay;
     taskNode.startTime = DateTime.Now;
     taskQue.timerWriteList.AddLast(taskNode);
     return(0);
 }
Exemplo n.º 2
0
        int ProcessTaskNodeData(TaskNode node)
        {
            if (node.processDataCallBack != null)
            {
                node.processDataCallBack(node.data);
            }

            if (node.releaseDataCallBack != null)
            {
                node.releaseDataCallBack(node.data);
            }

            TaskMsg taskMsg = node.msg;

            switch (taskMsg)
            {
            case TaskMsg.TMSG_QUIT:
                quitSem.Set();
                return(1);

            case TaskMsg.TMSG_PAUSE:
                pauseSem.WaitOne();
                pauseSem.Reset();
                break;
            }

            return(0);
        }
Exemplo n.º 3
0
        public int Pause()
        {
            TaskNode node = new TaskNode(TaskMsg.TMSG_PAUSE);

            if (PostTask(node, 0) != 0)
            {
                return(-1);
            }

            return(0);
        }
Exemplo n.º 4
0
        public int Quit()
        {
            Continue();

            TaskNode node = new TaskNode(TaskMsg.TMSG_QUIT);

            if (PostTask(node, 0) != 0)
            {
                return(-1);
            }

            quitSem.WaitOne();
            quitSem.Reset();
            return(0);
        }
Exemplo n.º 5
0
        int PostCommonTask(TaskNode taskNode, int delay)
        {
            int ret = 0;

            taskNode.delay = delay;
            if (delay != 0)
            {
                taskNode.startTime = DateTime.Now;
            }

            if (delay == 0)
            {
                taskQue.writeList.AddLast(taskNode);
            }
            else
            {
                taskQue.timerWriteList.AddLast(taskNode);
            }

            return(ret);
        }
Exemplo n.º 6
0
        public int PostTask(TaskNode taskNode, int delay = 0)
        {
            int ret = 0;

            Monitor.Enter(taskQue.lockobj);

            switch (taskNode.msg)
            {
            case TaskMsg.TMSG_TIMER_START:
            {
                ret = PostTimerTask(taskNode, -2000);
            }
            break;

            case TaskMsg.TMSG_TIMER_RUN:
            {
                ret = PostTimerTask(taskNode, delay);
            }
            break;

            case TaskMsg.TMSG_TIMER_STOP:
            {
                ret = PostCommonTask(taskNode, -1000);
            }
            break;

            default:
                ret = PostCommonTask(taskNode, delay);
                break;
            }

            Monitor.Exit(taskQue.lockobj);

            //设置任务处理可读信号
            readSem.Set();

            return(ret);
        }