Exemplo n.º 1
0
		public static SimpleAsyncResult RunWithLock (object locker, SimpleAsyncFunc func, SimpleAsyncCallback callback)
		{
			return Run (inner => {
				bool running = func (inner);
				if (running)
					Monitor.Exit (locker);
				return running;
			}, inner => {
				if (inner.GotException) {
					if (inner.CompletedSynchronously)
						Monitor.Exit (locker);
					callback (inner);
					return;
				}

				try {
					if (!inner.CompletedSynchronously)
						Monitor.Enter (locker);

					callback (inner);
				} finally {
					Monitor.Exit (locker);
				}
			});
		}
Exemplo n.º 2
0
        public static void RunWithLock(object locker, SimpleAsyncFunc func, SimpleAsyncCallback callback)
        {
            Run(inner => {
                bool running = func(inner);
                if (running)
                {
                    Monitor.Exit(locker);
                }
                return(running);
            }, inner => {
                if (inner.GotException)
                {
                    if (inner.CompletedSynchronously)
                    {
                        Monitor.Exit(locker);
                    }
                    callback(inner);
                    return;
                }

                try {
                    if (!inner.CompletedSynchronously)
                    {
                        Monitor.Enter(locker);
                    }

                    callback(inner);
                } finally {
                    Monitor.Exit(locker);
                }
            });
        }
Exemplo n.º 3
0
		public static void Run (SimpleAsyncFunc func, SimpleAsyncCallback callback)
		{
			var result = new SimpleAsyncResult (callback);
			try {
				if (!func (result))
					result.SetCompleted (true);
			} catch (Exception ex) {
				result.SetCompleted (true, ex);
			}
		}
Exemplo n.º 4
0
        public static void Run(SimpleAsyncFunc func, SimpleAsyncCallback callback)
        {
            var result = new SimpleAsyncResult(callback);

            try {
                if (!func(result))
                {
                    result.SetCompleted(true);
                }
            } catch (Exception ex) {
                result.SetCompleted(true, ex);
            }
        }