Example #1
0
        public Task <T> SendAsync <T>(Func <T> work, bool checkLock = true, int timeOut = TIME_OUT)
        {
            if (Settings.Ins.IsDebug)
            {
                return(checkActor.SendAsync(work, checkLock, timeOut));
            }

            FuncWrapper <T> at = new FuncWrapper <T>(work);

            at.Owner   = this;
            at.TimeOut = timeOut;
            actionBlock.SendAsync(at);
            return(at.Tcs.Task);
        }
        public Task <T> SendAsync <T>(Func <T> work, bool checkLock, int timeOut)
        {
            FuncWrapper <T> at = new FuncWrapper <T>(work);

            at.TimeOut = timeOut;
            lock (nodeLock)
            {
                int thId    = TaskScheduler.Current.Id;
                var newNode = new ActorNode();
                if (threadMap.ContainsKey(thId))
                {
                    newNode.Parent = threadMap[thId].activeNode;
                }
                newNode.Actor = cacheActor;
                if (work.Target == null || work.Method.DeclaringType.Name.Contains("<>c"))
                {
                    newNode.Trace = work.Method.DeclaringType.FullName + ":" + work.Method.Name + "(" + work.ToString() + ")";
                }
                else
                {
                    newNode.Trace = work.Target.GetType().FullName + ":" + work.Method.Name + "(" + work.ToString() + ")";
                }
                if (checkLock)
                {
                    checkNodeIlegal(newNode);
                }
                else
                {
                    newNode.Parent = null;
                }
                at.Node = newNode;
            }

            actionBlock.SendAsync(at);
            return(at.Tcs.Task);
        }