static void Main(string[] args)
        {
            Console.WriteLine("Main-Thread is " + Thread.CurrentThread.ManagedThreadId);

            SomeMethod a = new SomeMethod(Sum);

            Console.WriteLine("Aanroep asynchrone methode");

            // IAsyncResult asyncResult - dit representeert de status van de asynchrone operatie
            IAsyncResult asyncResult = a.BeginInvoke(5, 5, null, null);

            Thread.Sleep(200);

            // Tussendoor kan de status getest worden:
            Console.WriteLine("Moeilijke som uitgerekend? " + asyncResult.IsCompleted);

            Console.WriteLine("Het werk gaat door hier!! Tot de aanroep van EndInvoke...");

            // Nu gaan we wachten op het resultaat van de asynchrone aanroep:
            int result = a.EndInvoke(asyncResult);

            // Tussendoor kan de status getest worden:
            Console.WriteLine("Moeilijke som uitgerekend? " + asyncResult.IsCompleted);

            Console.WriteLine(result);
            Console.ReadKey();
        }
Example #2
0
    void Start()
    {
        DoStuff(AddOne, 1337);         //prints 1338
        DoStuff(SubOne, 1337);         //prints 1336

        SomeMethod del = AddOne;

        del += SubOne;
        DoStuff(del, 1337);         //prints 1337
    }
Example #3
0
    void Start()
    {
        DoStuff(AddOne, 1337);         //prints 1338
        DoStuff(SubOne, 1337);         //prints 1336

        SomeMethod del = AddOne;

        DoStuff(del, 1337);        //prints 1338
        float f = del(10);         //returns 11;
    }
Example #4
0
    void Start()
    {
        //anonymous lambda
        SomeMethod op = delegate(int num) { return(num + 1); };
        int        i  = op(3); //returns 4

        //same, but with lambda:
        op = (int num) => { return(num + 1); };
        i  = op(3);        //returns 4
    }
Example #5
0
 /// <summary>Catches the thrown error just for convenience</summary>
 static void PreventAppCrash(SomeMethod method)
 {
     try
     {
         method.Invoke();
         Console.WriteLine("ERROR: The method did not throw an exception");
     }
     catch (Exception e)
     {
         Console.WriteLine($"Exception successfully thrown: {e}");
     }
 }
Example #6
0
        public TClock(int time, SomeMethod tst)
        {
            this.Time       = time;
            this.PrintSmthg = tst;

            Thread newThread = new Thread(() =>
            {
                while (true)
                {
                    this.PrintSmthg();
                    Thread.Sleep((int)this.Time);
                }
            });

            newThread.Start();
        }
        public void TestMethod()
        {
            int x, y;

            SomeMethod.Method1(
                SomeMethod.Method2(
                    SomeMethod.Method3(
                        delegate
            {
                int y = 0;
            },
                        delegate
            {
                int y = 0;
            }),
                    delegate
            {
                int y = 0;
            },
                    delegate
            {
                int y = 0;
            }),
                delegate
            {
                int y = 0;
            },
                delegate
            {
                int y = 0;
            });

            SomeMethod.Method1(
                SomeMethod.Method2(
                    SomeMethod.Method3(
                        "this is " +
                        " a string",
                        y),
                    0,
                    1),
                x,
                y);
        }
Example #8
0
        public static void Task2()
        {
            SomeMethod Add = (x, y) => { return(x + y); };
            SomeMethod Sub = (x, y) => { return(x - y); };
            SomeMethod Mul = (x, y) => { return(x * y); };
            SomeMethod Div = (x, y) =>
            {
                if (y != 0)
                {
                    return(x / y);
                }
                else

                {
                    return(double.NaN);
                }
            };

            Console.WriteLine(Add(34, 2));
            Console.WriteLine(Sub(34, 2));
            Console.WriteLine(Mul(34, 2));
            Console.WriteLine(Div(34, 2));
        }
Example #9
0
    /// <summary>
    /// Wait some time before start some method.
    /// </summary>
    /// <param name="seconds"></param>
    /// <param name="method"></param>
    /// <returns></returns>
    IEnumerator Wait(float seconds, SomeMethod method)
    {
        yield return(new WaitForSeconds(seconds));

        method();
    }
Example #10
0
 private void Form1_Load(object sender, EventArgs e)
 {
     SomeMethod som = ChildMethod;
 }
Example #11
0
    public void DoStuff(SomeMethod method, int val)
    {
        float f = method(val);

        Debug.Log(f);
    }
Example #12
0
 private static void ProcessMethod(string title, SomeMethod someMethod)
 {
     Console.WriteLine(title);
     Console.WriteLine("---------------------------------------------------------------");
     someMethod();
     Console.WriteLine();
 }
Example #13
0
 public MyCommand(SomeMethod action)
 {
     this.action = action;
 }