コード例 #1
0
 public ComponentTimer(int timeInterval, doSomething handler)
 {
     this.timeInterval = timeInterval;
     this.thread = new Thread(run);
     this.thread.Priority = ThreadPriority.Lowest;
     TimesUp += handler;
 }
コード例 #2
0
        public static void DelegateTest3()
        {
            doSomething IamVoid = () => { Console.WriteLine("Hello there! I take nothing and return nothing"); };

            IamVoid();
            Console.ReadKey();
        }
コード例 #3
0
        public void test()
        {
            doSomething sum = delegate(int x, int y)
            {
                return(x + y);
            };

            Console.WriteLine("Delegate sum: " + sum(1, 2));
        }
コード例 #4
0
        static void Main(string[] args)
        {
            doSomething <double> del = Sum;

            Console.WriteLine(del?.Invoke(3, 2.5));
            Console.WriteLine(Exponent(1, 4.2, Sum));
            Console.WriteLine(Exponent(1, 4.2, del));
            Console.WriteLine(Exponent(1, 4.2, (a, b) => a + b));//если параметры передаются через ref/out обязательно указывать тип
            Console.WriteLine(Exponent(1, 4.2, (a, b) => Sum(a, b)));
            Func <int, double, double> func = Sum;

            Console.WriteLine(Exponent(1, 4.2, func.Invoke));
        }
コード例 #5
0
 void doTutorial()
 {
     if (!isSpeaking)
     {
         speak(ConstVar.narratorScript[step]);
         if (step < ConstVar.narratorScript.Count - 1)
         {
             step++;
         }
         else
         {
             isSleeping = true;
             handler    = null;
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// Applies content of <paramref name="pathToManifest"/> file to current context, invokes <paramref name="thingToDo"/> delegate, deactivates applied context.
        /// </summary>
        /// <param name="pathToManifest"></param>
        /// <param name="thingToDo"></param>
        /// <exception cref="FileNotFoundException"></exception>
        public static void UsingManifestDo(string pathToManifest, doSomething thingToDo)
        {
            var context = new ACTCTX();

            context.cbSize = Marshal.SizeOf(typeof(ACTCTX));
            bool wrongContextStructure = (context.cbSize != 0x20 && IntPtr.Size == 4) || // ensure stucture is right on 32 bits
                                         (context.cbSize != 52 && IntPtr.Size == 8); // the same for 64 bits

            if (wrongContextStructure)
            {
                throw new Exception("ACTCTX.cbSize is wrong");
            }
            context.lpSource = pathToManifest;

            IntPtr hActCtx = NativeMethods.CreateActCtx(ref context);

            if (hActCtx == Constants.INVALID_HANDLE_VALUE)
            {
                var error = Marshal.GetLastWin32Error();
                if (error == SYSTEM_ERROR_CODES.ERROR_FILE_NOT_FOUND)
                {
                    throw new System.IO.FileNotFoundException("Failed to find manifest", pathToManifest);
                }
                throw new Win32Exception(error);
            }
            try // with valid hActCtx
            {
                IntPtr cookie = IntPtr.Zero;
                if (!NativeMethods.ActivateActCtx(hActCtx, out cookie))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
                try // with activated context
                {
                    thingToDo();
                }
                finally
                {
                    NativeMethods.DeactivateActCtx(0, cookie);
                }
            }
            finally
            {
                NativeMethods.ReleaseActCtx(hActCtx);
            }
        }
コード例 #7
0
        /// <summary>
        /// Applies content of <paramref name="pathToManifest"/> file to current context, invokes <paramref name="thingToDo"/> delegate, deactivates applied context.
        /// </summary>
        /// <param name="pathToManifest"></param>
        /// <param name="thingToDo"></param>
        /// <exception cref="FileNotFoundException"></exception>
        public static void UsingManifestDo(string pathToManifest, doSomething thingToDo)
        {
            var context = new ACTCTX();
            context.cbSize = Marshal.SizeOf(typeof(ACTCTX));
            bool wrongContextStructure = (context.cbSize != 0x20 && IntPtr.Size == 4) // ensure stucture is right on 32 bits
                                  || (context.cbSize != 52 && IntPtr.Size == 8); // the same for 64 bits
            if (wrongContextStructure)
            {
                throw new Exception("ACTCTX.cbSize is wrong");
            }
            context.lpSource = pathToManifest;

            IntPtr hActCtx = NativeMethods.CreateActCtx(ref context);
            if (hActCtx == Constants.INVALID_HANDLE_VALUE)
            {
                var error = Marshal.GetLastWin32Error();
                if (error == SYSTEM_ERROR_CODES.ERROR_FILE_NOT_FOUND)
                {
                    throw new System.IO.FileNotFoundException("Failed to find manifest", pathToManifest);
                }
                throw new Win32Exception(error);
            }
            try // with valid hActCtx
            {
                IntPtr cookie = IntPtr.Zero;
                if (!NativeMethods.ActivateActCtx(hActCtx, out cookie))
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
                try // with activated context
                {
                    thingToDo();
                }
                finally
                {
                    NativeMethods.DeactivateActCtx(0, cookie);
                }
            }
            finally
            {
                NativeMethods.ReleaseActCtx(hActCtx);
            }
        }
コード例 #8
0
 /// <summary>Segue il copione descritto dentro il file narratorScript</summary>
 public void phase1()
 {
     handler = doTutorial;
 }
コード例 #9
0
        /// <summary>
        /// Given CLR assembly search manifest of it located in the same folder with .manifest suffix.
        /// Activates manifest found, invokes <paramref name="thingToDo"/> delegate, deactivates applied context.
        /// </summary>
        /// <param name="assembly"></param>
        /// <param name="action"></param>
        public static void UsingAssemblyManifestDo(System.Reflection.Assembly assembly, doSomething action)
        {
            var manifest = assembly.Location + ".manifest";

            UsingManifestDo(manifest, action);
        }
コード例 #10
0
 static double Exponent(int a, double b, doSomething <double> del)
 {
     return(Math.Pow(Math.E, del(a, b)));
 }
コード例 #11
0
 public LeafNode(Student etudiant, callReturn parent, doSomething act) : base(etudiant, parent)
 {
     returnToMe = childCompleted;
     run        = runAction;
     action     = act;
 }
コード例 #12
0
 /// <summary>
 /// Given CLR assembly search manifest of it located in the same folder with .manifest suffix.
 /// Activates manifest found, invokes <paramref name="thingToDo"/> delegate, deactivates applied context. 
 /// </summary>
 /// <param name="assembly"></param>
 /// <param name="action"></param>
 public static void UsingAssemblyManifestDo(System.Reflection.Assembly assembly, doSomething action)
 {
     var manifest = assembly.Location + ".manifest";
     UsingManifestDo(manifest, action);
 }