예제 #1
0
 public virtual int CfRunLoopAsyn()
 {
     if (this.taskRun != null)
     {
         if (!this.taskRun.Wait(100))
         {
             return(0);                        //正在工作
         }
     }
     //the CfRun is loop function
     this.taskRun = CtkCancelTask.RunOnce((ct) => { this.CfRunLoop(); });
     return(0);
 }
예제 #2
0
        public void NonStopConnectAsyn()
        {
            AbortNonStopConnect();

            this.NonStopTask = CtkCancelTask.RunOnce((ct) =>
            {
                while (!this.disposed && !ct.IsCancellationRequested)
                {
                    ct.ThrowIfCancellationRequested();
                    try
                    {
                        this.ConnectIfNo();
                    }
                    catch (Exception ex) { CtkLog.Write(ex); }
                    Thread.Sleep(this.IntervalTimeOfConnectCheck);
                }
            });
        }
예제 #3
0
        protected virtual void WriteAsyn(CtkLoggerEventArgs ea)
        {
            this.queue.Enqueue(ea);
            try
            {
                if (!Monitor.TryEnter(this, 1000))
                {
                    return;
                }
                if (this.task != null)
                {
                    //若還沒結束執行, 先return
                    if (!this.task.IsEnd())
                    {
                        return;
                    }
                    //若之前有, 把它清乾淨
                    using (var obj = this.task)
                        if (!obj.IsEnd())
                        {
                            obj.Cancel();
                        }
                }


                this.task = CtkCancelTask.RunLoop(() =>
                {
                    lock (this)
                    {
                        CtkLoggerEventArgs myea;
                        if (!this.queue.TryDequeue(out myea))
                        {
                            return(true);                                 //取不出來就下次再取
                        }
                        this.WriteSyn(myea);

                        //若Count等於零, 這個task會結束, IsEnd() = true
                        return(this.queue.Count > 0);
                    }
                });
            }
            finally { Monitor.Exit(this); }
        }
예제 #4
0
        public void Close()
        {
            this.CfIsRunning = false;
            this.areMsg.Set();//若在等訊號也通知結束等待

            if (this.taskRun != null)
            {
                this.taskRun.Cancel();//取消執行Task
                this.taskRun.Wait(1000);
                this.taskRun.Dispose();
                this.taskRun = null;
            }
            if (this.ProtoConn != null)
            {
                this.ProtoConn.Disconnect();
                this.ProtoConn.Dispose();
                this.ProtoConn = null;
            }
            CtkEventUtil.RemoveEventHandlersOfOwnerByFilter(this, (dlgt) => true);
        }