public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
        {
            string id;
            int    tid;

            lock (asyncCallbacks) {
                tid = asyncCounter++;
                id  = tid.ToString();
            }

            ObjectValue val  = null;
            bool        done = runner.Run(delegate {
                if (tid >= cancelTimestamp)
                {
                    val = evaluator();
                }
            },
                                          delegate {
                if (tid >= cancelTimestamp)
                {
                    OnEvaluationDone(id, val);
                }
            });

            if (done)
            {
                return(val);
            }
            else
            {
                return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags));
            }
        }
Exemplo n.º 2
0
        public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
        {
            string id;
            int    tid;

            lock (asyncCallbacks) {
                tid = asyncCounter++;
                id  = tid.ToString();
            }

            ObjectValue val  = null;
            bool        done = runner.Run(delegate {
                if (tid >= cancelTimestamp)
                {
                    val = evaluator();
                }
            },
                                          delegate {
                if (tid >= cancelTimestamp)
                {
                    OnEvaluationDone(id, val);
                }
            });

            if (done)
            {
                // 'val' may be null if the timed evaluator is disposed while evaluating
                return(val ?? ObjectValue.CreateUnknown(name));
            }

            return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags));
        }
        public ObjectValue Run(string name, ObjectValueFlags flags, ObjectEvaluatorDelegate evaluator)
        {
            string id;
            int    tid;

            lock (asyncCallbacks) {
                tid = asyncCounter++;
                id  = tid.ToString();
            }

            ObjectValue val  = null;
            bool        done = runner.Run(delegate {
                if (tid >= cancelTimestamp)
                {
                    var session = Session;
                    if (session == null || (flags == ObjectValueFlags.EvaluatingGroup))
                    {
                        // Cannot report timing if session is null. If a group is being
                        // evaluated then individual timings are not possible and must
                        // be done elsewhere.
                        val = evaluator();
                    }
                    else
                    {
                        using (var timer = session.EvaluationStats.StartTimer(name)) {
                            val = evaluator();
                            timer.Stop(val);
                        }
                    }
                }
            },
                                          delegate {
                if (tid >= cancelTimestamp)
                {
                    OnEvaluationDone(id, val);
                }
            });

            if (done)
            {
                // 'val' may be null if the timed evaluator is disposed while evaluating
                return(val ?? ObjectValue.CreateUnknown(name));
            }

            return(ObjectValue.CreateEvaluating(this, new ObjectPath(id, name), flags));
        }