Beispiel #1
0
        /// <summary>
        /// Shows usage of the synchronous FuncR method.
        /// </summary>
        /// <returns>The result of the operation.</returns>
        public static string FuncR_SyncSample()
        {
            int x = 0;

            // Create a synchronous, recursive func taking one parameter as input and returning a string.
            Func <int, string> a = FuncR <int, string> .Create((value, self) =>
            {
                // Loop recursively until value is reached.
                string s = x + ",";
                if (x < value)
                {
                    ++x;
                    s += self(value);
                }

                return(s);
            });

            // Execute the action with 4 loops, and return the result.
            return(a(4));
        }
Beispiel #2
0
        /// <summary>
        /// Shows usage of the asynchronous FuncR method.
        /// </summary>
        /// <returns>An async task containing the function result.</returns>
        public static async Task <string> FuncR_ASyncSample()
        {
            int x = 0;

            // Create a asynchronous, recursive func taking one parameter as input and returning a string.
            Func <int, Task <string> > a = FuncR <int, string> .Create(async (value, self) =>
            {
                // Loop recursively until value is reached.
                string s = x + ",";
                if (x < value)
                {
                    x  = await Task.FromResult <int>(x + 1);
                    s += await self(value);
                }

                return(s);
            });

            // Execute the action with 4 loops, wait for it to complete, and return the result.
            return(await a(4));
        }
Beispiel #3
0
 public delegate void FuncR <T1>(ref T1 arg1);    public static void LockedCall <T1>(string name, FuncR <T1> func, ref T1 arg1)
 {
     while (true)
     {
         try { var mutex = new Mutex(false, name); mutex.WaitOne();            func(ref arg1); mutex.ReleaseMutex(); } catch (AbandonedMutexException) { }
     }
 }
Beispiel #4
0
 public delegate U    FuncR <T1, U>(ref T1 arg1);    public static U    LockedCall <T1, U>(string name, FuncR <T1, U> func, ref T1 arg1)
 {
     while (true)
     {
         try { var mutex = new Mutex(false, name); mutex.WaitOne(); U result = func(ref arg1); mutex.ReleaseMutex(); return(result); } catch (AbandonedMutexException) { }
     }
 }
Beispiel #5
0
 public R GetReturnValueOfFuncR <R>(FuncR <R> actionR) =>
 actionR(out R returnValue).Return(returnValue);