Esempio n. 1
0
        /// <summary>
        /// Set value (synchronous). This should be called only once, 
        /// by the method / class who created it, when one wishes to signal
        /// the end of a chain / function / ...
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        internal MtResult SetValue(MtObject o)
        {
            lock (_sync) {
                if (o == null)
                    throw new Exception("Do not call MtResult.SetValue with null!");

                if (_hasValue)
                    throw new Exception("Already has value!");

                try
                {
                    _o = o;
                    _hasValue = true;

                    // Raise event!
                    _receivedValue.Set();

                    return this;
                }
                catch (Exception e)
                {
                    throw new Exception("Exception on MtResult.SetValue.", e);
                }
            }            
        }
Esempio n. 2
0
        internal MtResult SetValue(Func<object, MtObject> generateO)
        {
            // TODO Review this
            lock(_sync) 
            {
                if (generateO == null)
                    throw new Exception("Do not call MtResult.SetValue(async) with null!");

                if (_hasValue)
                    throw new Exception("Already has value!");

                try
                {
#if DEBUG && !SILVERLIGHT
                    MultiTasksRuntime.DebugDisplayInfo();
#endif

#if ALL_SYNC

                    {
                        var o = generateO(null);
#else // ALL_SYNC
                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        var o = generateO(state);    
#endif // ALL_SYNC

                        _o = o;
                        _hasValue = true;

                        // Raise event!
                        _receivedValue.Set();
#if ALL_SYNC
                    }
#else // ALL_SYNC
                    });
#endif // ALL_SYNC

                    return this;
                }
Esempio n. 3
0
        internal MtResult SetValue(Func<object, MtObject> generateO)
        {
            // TODO Review this
            lock(_sync)
            {
                if (generateO == null)
                    throw new Exception("Do not call MtResult.SetValue(async) with null!");

                if (_hasValue)
                    throw new Exception("Already has value!");

                try
                {
            #if DEBUG && !SILVERLIGHT
                    MultiTasksRuntime.DebugDisplayInfo();
            #endif

            #if ALL_SYNC

                    {
                        var o = generateO(null);
            #else // ALL_SYNC
                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        var o = generateO(state);
            #endif // ALL_SYNC

                        _o = o;
                        _hasValue = true;

                        // Raise event!
                        _receivedValue.Set();
            #if ALL_SYNC
                    }
            #else // ALL_SYNC
                    });
            #endif // ALL_SYNC

                    return this;
                }
                catch (Exception e)
                {
                    throw new Exception("Exception on MtResult.SetValue(async).", e);
                }
            }
        }
Esempio n. 4
0
 public static MtResult CreateAndWrap(MtObject o)
 {
     return (new MtResult().SetValue(o));
 }
Esempio n. 5
0
        /// <summary>
        /// Set value (synchronous). This should be called only once, 
        /// by the method / class who created it, when one wishes to signal
        /// the end of a chain / function / ...
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        internal MtResult SetValue(MtObject o)
        {
            lock (_sync) {
                if (o == null)
                    throw new Exception("Do not call MtResult.SetValue with null!");

                if (_hasValue)
                    throw new Exception("Already has value!");

                try
                {
                    _o = o;
                    _hasValue = true;

                    // Raise event!
                    _receivedValue.Set();

                    return this;
                }
                catch (Exception e)
                {
                    throw new Exception("Exception on MtResult.SetValue.", e);
                }
            }
        }