Example #1
0
        public static void testDelegate()
        {
            DelegateToMethod aDelegate = new DelegateToMethod(Math.Add);
            DelegateToMethod mDelegate = new DelegateToMethod(Math.Multiply);
            DelegateToMethod dDelegate = new DelegateToMethod(Math.Divide);

            Console.WriteLine("Calling the method Math.Add() through the aDelegate object");
            Console.WriteLine(aDelegate(5, 5));
            Console.WriteLine("Calling the method Math.Multiply() through the mDelegate object");
            Console.WriteLine(mDelegate(5, 5));
            Console.WriteLine("Calling the method Math.Divide() through the dDelegate object");
            Console.WriteLine(dDelegate(5, 5));
        }
        private void Watcher_Process(object sender, FileSystemEventArgs e)
        {
            lock (lockObject)
            {
                Watcher_Turn(false);

                Thread thread_Watcher_Process = new Thread(() =>
                {
                    lock (threads)
                    {
                        foreach (var thr in threads)
                        {
                            if (thr != null)
                            {
                                thr.Abort();
                            }
                        }

                        threads = new List <Thread>();

                        Thread.CurrentThread.Name = "Watcher_" + this.MethodName;
                        threads.Add(Thread.CurrentThread);
                    }

                    Thread.Sleep(time);

                    Thread threadCallProcess = new Thread(() =>
                    {
                        DelegateToMethod.GetTypeOfDelegate(MethodName, ClassName).Item1.DynamicInvoke(Config.ToArray());
                    });
                    threadCallProcess.Start();
                    threadCallProcess.Join();

                    threads.Remove(Thread.CurrentThread);

                    Times++;
                });
                thread_Watcher_Process.Start();
                thread_Watcher_Process.Join();

                Watcher_Turn(true);
            }
        }