Пример #1
0
        /// <summary>
        /// Shows usage of the asynchronous ActionR method.
        /// </summary>
        /// <returns>An async task.</returns>
        public static async Task ActionR_AsyncSample()
        {
            int x = 0;

            // Create an asynchronous, recursive action taking one parameter as input.
            Func <int, Task> a = ActionR <int> .Create(async (value, self) =>
            {
                // Loop recursively until value is reached.
                if (x < value)
                {
                    x = await Task.FromResult <int>(x + 1);
                    await self(value);
                }
            });

            // Execut the action with 4 loops, and wait for it to complete.
            await a(4);
        }
Пример #2
0
        /// <summary>
        /// Shows usage of the synchronous ActionR method.
        /// </summary>
        public static void ActionR_SyncSample()
        {
            int x = 0;

            // Create a synchronous, recursive action taking one parameter as input.
            Action <int> a = ActionR <int> .Create((value, self) =>
            {
                // Loop recursively until value is reached.
                if (x < value)
                {
                    ++x;
                    self(value);
                }
            });

            // Execute the action with 4 loops.
            a(4);
        }