Пример #1
0
        //Ein Delegat kann einen optionalen Parameter angeben AUCH WENN die Funktion der sie zugewiesen ist einen Parameter vorschreibt. Trotzdem darf das Parameterfeld des Delegaten nicht leer sein, solange die Methode Parameter verlangt. Der Delegat gibt bei leerem Parameterfeld den default Wert des optionalen Parameters(also 0) an(weil: int i = 0).
        //Delegaten die außerhalb von Klassen deklariert sind können nur statische Methoden annehmen.
        public void InvokeDelegates()
        {
            SimpleDelegate simpleDelegate = new SimpleDelegate(DelegateMethod); // Dem Delegaten "simpleDelegate" wird die Methode "DelegateMethod" zugewiesen
                                                                                //Anstatt die Methode mit dem new Modifizierer und dem Delegatennamen einem Delegaten zuzuweisen kann man auch schreiben:
            SimpleDelegate simple = DelegateMethod;

            simpleDelegate += new SimpleDelegate(AnotherDelegateMethod); //Der Delegat "simpleDelegate" hat eine weitere Methode aufgenommen. Ein Delegat der Verweise zu mehreren Methoden hat nennt man "Multicast-Delegaten". Er wird bei Ausführung die beiden Methoden nacheinander aufrufen.
                                                                         //Delegaten kann man auf mehrere Weisen Multicasten. Man kann entweder die Funktion ".Combine()" aufrufen oder die Delegaten mit dem "+=" Operator überladen.
            simpleDelegate.Invoke();                                     //".Invoke()" ist ein Befehl der die ausführung der Methoden verlangt. Wenn der Delegat nicht vom Typ "void" ist kann man den Rückgabewert des Delegaten auch in eine Variable laden. (z.b. int result = simpleDelegate; / int result = simpleDelegate.Invoke(); Console.WriteLine(result);)

            //Statt die ".Invoke()" Methode zu nutzen kann man Delegaten auch wie normale Methoden aufrufen wie unten:
            simple();


            Console.WriteLine("Generische Delegaten ausführen?[y/n]");
            switch (Console.ReadLine().ToLower())
            {
            case "y":
                GenericDelegates();
                break;

            case "n":
            default:
                return;
            }
        }
Пример #2
0
 /// <summary>
 /// SafeThread constructor using SimpleDelegate object for anonymous methods, e.g.
 /// <code>
 ///     SafeThread safeThrd = new SafeThread((SimpleDelegate) delegate { dosomething(); });
 /// </code>
 /// </summary>
 /// <param name="sd"></param>
 public SafeThread(SimpleDelegate sd)
     : this()
 {
     _dlg         = sd;
     _pts         = new ParameterizedThreadStart(this.CallDelegate);
     ThreadObject = new Thread(_pts);
 }
Пример #3
0
        public void cDhcp_Announced(cDHCPStruct d_DHCP, string MacId)
        {
            string str = string.Empty;

            if (MacId.StartsWith(MacMask) == true)
            {
                //options should be filled with valid data
                d_DHCP.dData.IPAddr      = GetIPAdd();
                d_DHCP.dData.SubMask     = "255.255.0.0";
                d_DHCP.dData.LeaseTime   = 2000;
                d_DHCP.dData.ServerName  = "Small DHCP Server";
                d_DHCP.dData.MyIP        = AdapterIP;
                d_DHCP.dData.RouterIP    = "0.0.0.0";
                d_DHCP.dData.LogServerIP = "0.0.0.0";
                d_DHCP.dData.DomainIP    = "0.0.0.0";
                str = "IP requested for Mac: " + MacId;
            }
            else
            {
                str = "Mac: " + MacId + " is not part of the mask!";
            }
            cDhcp.SendDHCPMessage(DHCPMsgType.DHCPOFFER, d_DHCP);
            SimpleDelegate lst = delegate
            {
                listBox1.Items.Add(str);
            };

            Invoke(lst);
            //Application.DoEvents()
        }
Пример #4
0
        public static void BackgroundTaskNoCallback(SimpleDelegate method)
        {
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw.RunWorkerAsync(method);
        }
Пример #5
0
        void IHashWorkManager.QueueTask(SimpleDelegate task)
        {
            // Enqueue item in list
            TaskResetEvent item = new TaskResetEvent(task, new ManualResetEvent(false));

            lock (TaskQueueLock) {
                item.BeginUse();
                TaskQueueItems.Add(item);
            }

            // Enqueu item in thread pool
            ThreadPool.QueueUserWorkItem((object threadContext) => {
                // Task will be performed
                item.Task();

                // Wait handle will be reset
                lock (TaskQueueLock) {
                    item.WaitHandle.Set();
                    item.EndUse();

                    // If item is no longer in use, item will be removed from list and disposed
                    if (!item.InUse)
                    {
                        TaskQueueItems.Remove(item);
                        item.WaitHandle.Close();
                    }
                }
            });
        }
Пример #6
0
	static public int test_0_test () {
		SimpleDelegate t;
		SimpleDelegate d1 = new SimpleDelegate (F1);
		SimpleDelegate d2 = new SimpleDelegate (F2);
		SimpleDelegate d3 = new SimpleDelegate (F3);

		SimpleDelegate d12 = d1 + d2;
		SimpleDelegate d13 = d1 + d3;
		SimpleDelegate d23 = d2 + d3;
		SimpleDelegate d123 = d1 + d2 + d3;

		v = 0;
		t = d123 - d13;
		t ();
		if (v != 7)
			return 1;
		
		v = 0;
		t = d123 - d12;
		t ();
		if (v != 4)
			return 1;
		
		v = 0;
		t = d123 - d23;
		t ();
		if (v != 1)
			return 1;
		
		
		return 0;
	}
Пример #7
0
        public void ProcessCommand(string cmd)
        {
            m_commandLine.Enabled = false;

            //
            // ProcessCommand may block, so call it asynchronously
            // to keep UI responsive.
            //
            SimpleDelegate d = delegate
            {
                m_cmdProc.ProcessCommand(
                    cmd,
                    delegate(string text){
                    this.Invoke((SimpleDelegate) delegate
                    {
                        Output(text);
                    });
                });
                this.Invoke((SimpleDelegate) delegate
                {
                    m_commandLine.Enabled = true;
                    Output("\n");
                    m_commandLine.Focus();
                });
            };

            d.BeginInvoke(null, null);
        }
Пример #8
0
        public static void Run()
        {
            // Using lambda operator

            FormatDateTime czechFormat = dateTime => $"{dateTime:dd.MM.yyyy}";

            czechFormat += dateTime => $"{dateTime:dd.MM.yy}";

            Console.WriteLine($"Czech format: {czechFormat(DateTime.Now)}");

            // Asking for invocation list

            var invocations = czechFormat.GetInvocationList();

            foreach (var invocation in invocations)
            {
                Console.WriteLine($"invocation.Method: {invocation.Method}");
                Console.WriteLine($"invocation.Target: {invocation.Target}");
            }

            // Using asynchronous support

            SimpleDelegate simpleDelegate = () => { Thread.Sleep(1000); };

            Console.WriteLine("The delegate invoked asynchronously is starting ...");

            simpleDelegate.BeginInvoke(HandleEndOfSimpleDelegateInvocation, null);

            Console.WriteLine("Processing is going on ...");
        }
Пример #9
0
    static int Main()
    {
        SimpleDelegate d      = new SimpleDelegate(async_func_throws);
        AsyncCallback  ac     = new AsyncCallback(async_callback);
        string         state1 = "STATE1";

        // Call delegate via ThreadPool and check that the exception is rethrown correctly
        IAsyncResult ar1 = d.BeginInvoke(1, ac, state1);

        while (cb_state == 0)
        {
            Thread.Sleep(0);
        }

        try {
            d.EndInvoke(ar1);
            Console.WriteLine("NO EXCEPTION");
            return(1);
        } catch (AsyncException) {
            Console.WriteLine("received exception ... OK");
            return(0);
        } catch (Exception e) {
            Console.WriteLine("wrong exception {0}", e);
            return(3);
        }
    }
Пример #10
0
 public void OnButton()
 {
     ContextText.text = string.Empty;
     OnButtonPress?.Invoke();
     OnButtonPress = null;
     gameObject.SetActive(false);
 }
Пример #11
0
    private IEnumerator UserLoginCoroutine(string user, string password, SimpleDelegate <MeridianData.UserLoginResult> userLoginDelegate)
    {
        // Build json by hand
        string jsonString = "{ mail:'" + user + "', password:'******' }";

        WWW www = MeridianCommunications.POST("/Catalog/Login", jsonString);

        yield return(www);

        MeridianData.UserLoginResult result = null;

        if (www.error == null)
        {
            // Since JSon comes in the form of an array we must wrap data around a class.
            result = JsonUtility.FromJson <MeridianData.UserLoginResult>("{\"userList\":" + www.text + "}");
        }
        else
        {
        }

        if (userLoginDelegate != null)
        {
            userLoginDelegate(result);
        }
    }
Пример #12
0
	static int Main () {
		SimpleDelegate d1 = new SimpleDelegate (Method);
		SimpleDelegate d2 = new SimpleDelegate (Method);

		AsyncCallback ac = new AsyncCallback (Callback);
		
		IAsyncResult ar1 = d1.BeginInvoke (1, ac, null);
		IAsyncResult ar2 = d2.BeginInvoke (2, ac, null);

		try {
			d1.EndInvoke (ar2);
			return 1;
		} catch (InvalidOperationException) {
			// expected
		}

		try {
			d2.EndInvoke (ar1);
			return 2;
		} catch (InvalidOperationException) {
			// expected
		}

		if (1 != d1.EndInvoke (ar1)) return 3;
		if (2 != d2.EndInvoke (ar2)) return 4;

		return 0;
	}
Пример #13
0
 static int Main()
 {
     SimpleDelegate
     d
     =
     new
     SimpleDelegate
     (Add);
     SimpleDelegate
     d2
     =
     new
     SimpleDelegate
     (Add2);
     if
     (mono_invoke_delegate
     (d)
     !=
     5)
     return
     1;
     if
     (mono_invoke_delegate
     (d2)
     !=
     5)
     return
     1;
     return
     0;
 }
Пример #14
0
 /// <summary> 모든 재화에 전부 다 콜백 검 </summary>
 static public void RegisterOnChangedValueCallback(SimpleDelegate reciever)
 {
     foreach (Money m in moneyDic.Values)
     {
         m.onChangedValue += reciever;
     }
 }
Пример #15
0
        public static void Main()   //
        {
            //SimpleDelegate simp = new SimpleDelegate(SimpleMethod);
            //simp();

            SimpleDelegate simp1, simp2, simp3, simp4;

            simp1 = new SimpleDelegate(SimpleMethod1);
            simp2 = new SimpleDelegate(SimpleMethod2);
            simp3 = new SimpleDelegate(SimpleMethod3);

            simp4 = simp1 + simp2 + simp3; //chaining method
            simp4();                       //it will invoke all of the four methods..it is multicast delegates

            //or                                        //simp1 = new SimpleDelegate(SimpleMethod_1);
            //simp1 += SimpleMethod_2
            simp1 += SimpleMethod2;                  //int deloutputval = -1;
            simp1 += SimpleMethod3;                  //
            simp1 -= SimpleMethod1;
            simp1();


            //in return type case
            // SimpleDelegate simp = new SimpleDelegate(SimpleMethod_1);
            // simp1 += SimpleMethod_2;
            // int storevar = simp();      //it will have 2 stored in it...the lastmethod value
        }
Пример #16
0
 public static void Remove_OnQuit(SimpleDelegate toremove)
 {
     lock (quit_handlers)
     {
         quit_handlers.Remove(toremove);
     }
 }
Пример #17
0
 /// <summary>
 /// SafeThread constructor using SimpleDelegate object for anonymous methods, e.g.
 /// <code>
 ///     SafeThread safeThrd = new SafeThread((SimpleDelegate) delegate { dosomething(); });
 /// </code>
 /// </summary>
 /// <param name="sd"></param>
 public SafeThread(SimpleDelegate sd)
     : this()
 {
     dlg     = sd;
     _Pts    = new ParameterizedThreadStart(this.CallDelegate);
     _thread = new Thread(_Pts);
 }
Пример #18
0
 void MultiCall(SimpleDelegate d, int count)
 {
     for (int i = 0; i < count; i++)
     {
         d();
     }
 }
Пример #19
0
        public void cDhcp_Request(cDHCPStruct d_DHCP, string MacId)
        {
            string str = string.Empty;

            if (MacId.StartsWith(MacMask) == true)
            {
                //announced so then send the offer
                d_DHCP.dData.IPAddr      = GetIPAdd();
                d_DHCP.dData.SubMask     = "255.255.0.0";
                d_DHCP.dData.LeaseTime   = 2000;
                d_DHCP.dData.ServerName  = "tiny DHCP Server";
                d_DHCP.dData.MyIP        = AdapterIP;
                d_DHCP.dData.RouterIP    = "0.0.0.0";
                d_DHCP.dData.LogServerIP = "0.0.0.0";
                d_DHCP.dData.DomainIP    = "0.0.0.0";
                cDhcp.SendDHCPMessage(DHCPMsgType.DHCPACK, d_DHCP);
                str = "IP " + d_DHCP.dData.IPAddr + " Assigned to Mac: " + MacId;
            }
            else
            {
                str = "Mac: " + MacId + " is not part of the mask!";
            }
            SimpleDelegate lst = delegate
            {
                listBox1.Items.Add(str);
            };

            Invoke(lst);
        }
Пример #20
0
 /// <summary>
 /// When creates a new class
 /// </summary>
 /// <param name="del"></param>
 public Window_SetMember(SimpleDelegate del)
 {
     curclass = new SClass();
     InitializeComponent();
     this.Title = "반 정보 추가";
     setMemberCallback = del;
 }
Пример #21
0
    static int Main()
    {
        SimpleDelegate d      = new SimpleDelegate(F);
        AsyncCallback  ac     = new AsyncCallback(async_callback);
        string         state1 = "STATE1";
        string         state2 = "STATE2";
        string         state3 = "STATE3";
        string         state4 = "STATE4";
        int            fin    = 0;

        IAsyncResult ar1 = d.BeginInvoke(1, ac, state1);
        IAsyncResult ar2 = d.BeginInvoke(2, ac, state2);
        IAsyncResult ar3 = d.BeginInvoke(3, ac, state3);
        IAsyncResult ar4 = d.BeginInvoke(4, ac, state4);

        int res = d.EndInvoke(ar1);

        Console.WriteLine("Result = " + res);

        try
        {
            d.EndInvoke(ar1);
        }
        catch (InvalidOperationException)
        {
            Console.WriteLine("cant execute EndInvoke twice ... OK");
        }

        ar1.AsyncWaitHandle.WaitOne();
        if (ar1.IsCompleted)
        {
            fin++;
        }
        Console.WriteLine("completed1: " + ar1.IsCompleted);
        ar2.AsyncWaitHandle.WaitOne();
        if (ar2.IsCompleted)
        {
            fin++;
        }
        Console.WriteLine("completed2: " + ar2.IsCompleted);
        ar3.AsyncWaitHandle.WaitOne();
        if (ar3.IsCompleted)
        {
            fin++;
        }
        Console.WriteLine("completed3: " + ar3.IsCompleted);
        ar4.AsyncWaitHandle.WaitOne();
        if (ar4.IsCompleted)
        {
            fin++;
        }
        Console.WriteLine("completed4: " + ar4.IsCompleted);

        if (fin != 4)
        {
            return(1);
        }

        return(0);
    }
Пример #22
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Console.OutputEncoding = Encoding.Unicode;
            bool IsCalled = false;

            while (true)
            {
                TimerAndDelegate some = new TimerAndDelegate();
                //Console.WriteLine(some.Seconds);
                some = new TimerAndDelegate();

                SimpleDelegate something = new SimpleDelegate(TimerAndDelegate.Test);
                SimpleDelegate getJoke   = new SimpleDelegate(JokesDataBase.GetRandomJoke);
                if (some.Seconds == 30 && IsCalled == false)
                {
                    something.DynamicInvoke();
                    getJoke.DynamicInvoke();
                    Console.WriteLine();
                    IsCalled = true;
                }
                if (some.Seconds == 31)
                {
                    IsCalled = false;
                }
            }
        }
Пример #23
0
    static int Main()
    {
        SimpleDelegate d1 = new SimpleDelegate(Method);
        SimpleDelegate d2 = new SimpleDelegate(Method);

        AsyncCallback ac = new AsyncCallback(Callback);

        IAsyncResult ar1 = d1.BeginInvoke(1, ac, null);
        IAsyncResult ar2 = d2.BeginInvoke(2, ac, null);

        try {
            d1.EndInvoke(ar2);
            return(1);
        } catch (InvalidOperationException) {
            // expected
        }

        try {
            d2.EndInvoke(ar1);
            return(2);
        } catch (InvalidOperationException) {
            // expected
        }

        if (1 != d1.EndInvoke(ar1))
        {
            return(3);
        }
        if (2 != d2.EndInvoke(ar2))
        {
            return(4);
        }

        return(0);
    }
Пример #24
0
    static int Main()
    {
        SimpleDelegate d      = new SimpleDelegate(F);
        AsyncCallback  ac     = new AsyncCallback(async_callback);
        string         state1 = "STATE1";
        int            res    = 0;

        IAsyncResult ar1 = d.BeginInvoke(1, ac, state1);

        ar1.AsyncWaitHandle.WaitOne();

        try {
            res = d.EndInvoke(ar1);

            while (cb_state == 0)
            {
                Thread.Sleep(0);
            }
        } catch (NotImplementedException) {
            res = 1;
            Console.WriteLine("received exception ... OK");
        }

        if (cb_state != 1)
        {
            return(1);
        }

        if (res != 1)
        {
            return(2);
        }

        return(0);
    }
Пример #25
0
 public void Repeat3Times(SimpleDelegate sd)
 {
     for (int i = 0; i < 3; i++)
     {
         sd();
     }
 }
Пример #26
0
    /// <summary>
    /// Checks if there's an active internet connection by reching TakTakTak server.
    /// </summary>
    /// <returns>The internet connection.</returns>
    /// <param name="connectionOKDelegate">Connection OK delegate.</param>
    /// <param name="noConnectionDelegate">No connection delegate.</param>
    static public IEnumerator CheckInternetConnection(SimpleDelegate connectionOKDelegate, SimpleDelegate noConnectionDelegate)
    {
        Debug.Log("Checking Internet connection...");

        WWW www = new WWW("https://www.google.com");

        yield return(www);

        if (www.error != null)
        {
            // Internet connection error
            Debug.LogError("Internet connection error: " + www.error);

            if (noConnectionDelegate != null)
            {
                noConnectionDelegate();
            }
        }
        else
        {
            // Internet connection OK
            Debug.Log("Internet connection found!");

            if (connectionOKDelegate != null)
            {
                connectionOKDelegate();
            }
        }
    }
Пример #27
0
        private void DoExport()
        {
            try
            {
                dateToExport = DateTime.MinValue;
                //dateToExport = new DateTime(2016, 3, 14);

                ExcelSearchCriteria c = _view.CriteriaSettings;


                StampaExcelSettings settings = new StampaExcelSettings(_view.InventarioScriviTipoInventario, _view.InventarioScriviIntestazioniTipoInventario, _view.InventarioRigheFraTipiInventario, _view.InventarioRigaIniziale, _view.InventarioDisegnaOrizzontalmente, _view.InventarioColonnaIniziale, _view.InventarioFeneal, _view.VisibilityTabPreventivo, _view.VisibilityTabStatoPatrimoniale, dateToExport);


                if (_view.IsFreeTemplate)
                {
                    _service.ExportToExcel(_view.ModelloStampa(), c, settings, "Rendiconto" + _view.MainHeader);
                }
                else
                {
                    _service.ExportToExcel(_view.ModelloStampa(_service.RendicontoHeader.IsRegionale), c, settings, "Rendiconto" + _view.MainHeader);
                }
            }
            catch (Exception ex)
            {
                _view.GetSimpleMessageNotificator().Show(ex.Message, "Errore", MessageType.Error);
            }
            finally
            {
                SimpleDelegate d = _view.HidePanel;
                _view.Invoke(d);
            }
        }
Пример #28
0
        public void UpdateMessage()
        {
            if (InvokeRequired)
            {
                SimpleDelegate simpleDelegate = new SimpleDelegate(UpdateMessage);
                Invoke(simpleDelegate);
            }
            else
            {
                listMessange.Items.Clear();

                if (listUser.SelectedItem != null)
                {
                    if (listUser.SelectedItem is User user)
                    {
                        foreach (Message message in CDataController.Messages)
                        {
                            if (message.Receiver == user.Email && message.Sender == CConnectionController.LoginUser.Email || message.Receiver == CConnectionController.LoginUser.Email && message.Sender == user.Email)
                            {
                                listMessange.Items.Add(message);
                            }
                        }
                    }
                }
            }
        }
Пример #29
0
 public static void Add_OnQuit(SimpleDelegate toadd)
 {
     lock (quit_handlers)
     {
         quit_handlers.Add(toadd);
     }
 }
Пример #30
0
	static int Main () {
		SimpleDelegate d = new SimpleDelegate (F);
		AsyncCallback ac = new AsyncCallback (async_callback);
		string state1 = "STATE1";
		int res = 0;
		
		IAsyncResult ar1 = d.BeginInvoke (1, ac, state1);

		ar1.AsyncWaitHandle.WaitOne ();

		try {
			res = d.EndInvoke (ar1);
		} catch (NotImplementedException) {
			res = 1;
			Console.WriteLine ("received exception ... OK");
		}

		while (cb_state == 0)
			Thread.Sleep (0);
		
		if (cb_state != 1)
			return 1;
		
		if (res != 1)
			return 2;

		return 0;
	}
Пример #31
0
 public static void Main()
 {
     // Instantiation of а delegate
     SimpleDelegate d = new SimpleDelegate(TestFunction);
     
     // Invocation of the method, pointed by a delegate
     d("test");
 }
Пример #32
0
 public void UpdateContextMenu(string buttonLabel, string text, SimpleDelegate onButtonPress)
 {
     Panel.SetActive(true);
     OnButtonPress = onButtonPress;
     ContextButton.interactable = OnButtonPress != null;
     ContextButtonLabel.text    = buttonLabel;
     ContextText.text           = text;
 }
        public void Instantiate_and_invoke_a_delegate_using_the_CSharp1_syntax()
        {
            // Instantiation
            var simpleDelegate = new SimpleDelegate(printSquareRoot);

            // Invocation
            simpleDelegate(49);
        }
        static void Main()
        {
            SimpleDelegate del = new SimpleDelegate(TestMethod);
            del += TestMethod;
            del += Console.WriteLine;

            del("Hello");
        }
Пример #35
0
            public static void Display()
            {
                // Instantiate the delegate
                SimpleDelegate d = new SimpleDelegate(TestMethod);

                // Invocation of the method, pointed by delegate
                d("test");
            }
Пример #36
0
        static void Main(string[] args)
        {
            SimpleDelegate someDelegate = new SimpleDelegate(PrintSmile);

            someDelegate();

            Timer.setInterval(new Action(() => PrintSmile()), 1);
        }
Пример #37
0
        public static void Main()
        {
            // Instantiation-- we set this simpleDelegate to MyFunc
            SimpleDelegate simpleDelegate = new SimpleDelegate(MyFunc);

            // Invocation-- MyFunc is called.
            simpleDelegate();
        }
        static void Main(string[] args)
        {
            SimpleDelegate multiplication_delegate = new SimpleDelegate(Multiplication);
            SimpleDelegate addition_delegate       = new SimpleDelegate(Addition);

            Console.WriteLine("multiplication delegate : " + multiplication_delegate(21, 10));
            Console.WriteLine("addition delegate : " + addition_delegate(5, 27));
        }
Пример #39
0
 public FormPreview(Image img, SimpleDelegate extra)
 {
     InitializeComponent();
     this.extra = extra;
     pictureBox.Image = img;
     toolStripComboBoxShapeType.Items.AddRange(Enum.GetValues(typeof(ShapeType)).Cast<ShapeType>().Select(t => t.ToString()).ToArray());
     toolStripComboBoxShapeType.SelectedIndex = 0;
     this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
 }
Пример #40
0
 /// <summary>
 /// When modifys existing class
 /// </summary>
 /// <param name="curclass"></param>
 /// <param name="del"></param>
 public Window_SetMember(SClass curclass, SimpleDelegate del)
 {
     InitializeComponent();
     this.Title = "반 정보 수정";
     this.setMemberCallback = del;
     this.curclass = curclass;
     tb_ClassMember.Text = YangpaData.ConvertArrayToComma(curclass.Students);
     tb_ClassCaptain.Text = YangpaData.ConvertArrayToComma(curclass.Captains);
     tb_ClassName.Text = curclass.Name;
 }
Пример #41
0
        public void Callback(SimpleDelegate del)
        {
            if (del != null)
                del();

            if (SimpleEvent != null)
                SimpleEvent();

            SimpleEvent += new SimpleDelegate(SourceTests_SimpleEvent);
        }
Пример #42
0
 static void Main(string[] args)
 {
     int interval = 2;
     SimpleDelegate method = new SimpleDelegate(PrintMethod);
     StartTimer(interval, method);
     while (!Console.KeyAvailable)
     {
     }
     StopTimer();
 }
        public static void PrintEverySecond(int[] array)
        {
            var simpleDelegate = new SimpleDelegate(PrintUsingLINQ);

            while (true)
            {
                simpleDelegate(array);
                System.Threading.Thread.Sleep(1000);
            }
        }
Пример #44
0
 private static void ExecuteTimer(SimpleDelegate d, int deley)
 {
     while (true)
     {
         DateTime time = DateTime.Now;
         d(time);
         Thread.Sleep(deley);
         Console.Clear();
     }
 }
 private static void SafeInvokeDelegate(SimpleDelegate x)
 {
     foreach (var target in x.GetInvocationList()) {
         try {
             target.DynamicInvoke();
         } catch (Exception e) {
             Log.Logger.ErrorException("Exception invoking delegate", e);
         }
     }
 }
 static void Main()
 {
     Console.Write("t=");
     int t = int.Parse(Console.ReadLine());
     SimpleDelegate d = new SimpleDelegate(TestMethod);
     while (true)
     {
         d(t);
     }
 }
	static void Main()
	{
		// Instantiate the delegate
		SimpleDelegate d = new SimpleDelegate(TestMethod);

		// The above can be written in a shorter way
		d = TestMethod;

		// Invocation of the method, pointed by delegate
		d("test");
	}
Пример #48
0
        public void LoadAsync(String addres, SimpleDelegate loadCompleted)
        {
            Lines = new List<int[]>();
            int size;
            string midifile;
            using (StreamReader file = new StreamReader("Content/" + addres))
            {
                char[] delimiter = { ' ', ':' };
                Name = file.ReadLine();
                midifile = file.ReadLine();
                Instruments = file.ReadLine().Split(delimiter);
                int[] temp;
                string[] columns;
                string column;
                column = file.ReadLine();
                size = Convert.ToInt32(column);
                for (int i = 0; i < Instruments.Length; i++)
                {
                    int[] lineArray = new int[size];
                    Lines.Add(lineArray);
                }
                int[] pre = new int[Instruments.Length];

                for (int d = 0; d < Instruments.Length; d++)
                {
                    pre[d] = 0;
                }

                while ((column = file.ReadLine()) != null)
                {
                    columns = column.Split(delimiter);
                    temp = Lines.ElementAt(Convert.ToInt32(columns[1]));
                    for (int r = pre[Convert.ToInt32(columns[1])]; r < Convert.ToInt32(columns[0]); r++)
                    {
                        temp[r] = temp[pre[Convert.ToInt32(columns[1])]];
                    }
                    temp[Convert.ToInt32(columns[0])] = Convert.ToInt32(columns[2]);
                    pre[Convert.ToInt32(columns[1])] = Convert.ToInt32(columns[0]);

                }
                for (int i = 0; i < Instruments.Length; i++)
                {
                    temp = Lines.ElementAt(i);
                    for (int d = pre[i]; d < size; d++)
                    {
                        temp[d] = temp[pre[i]];
                    }
                }
            }
            Midi = new Audio.Midi.Song();
            Midi.LoadAsync(midifile, delegate() { if (loadCompleted != null) loadCompleted(); });
        }
Пример #49
0
 static void StartTimer(int interval, SimpleDelegate method)
 {
     Console.WriteLine("Press any key to stop the timer\n");
     timerThread = new Thread(() =>
     {
         while (true)
         {
             method(interval);
             Thread.Sleep(interval * 1000);
         }
     });
     timerThread.Start();
 }
Пример #50
0
	public static int Main () {
		SimpleDelegate d = new SimpleDelegate (F);
		AsyncCallback ac = new AsyncCallback (async_callback);
		
		IAsyncResult ar1 = d.BeginInvoke (cb_state, ac, cb_state);

		ar1.AsyncWaitHandle.WaitOne ();


		while (cb_state < 5)
			Thread.Sleep (200);

		return 0;
	}
Пример #51
0
	public static int Main ()
	{
		SimpleDelegate dv = new SimpleDelegate (new VirtualDelegate1 ().OnEvent);
		SimpleDelegate dnv = new SimpleDelegate (new NonVirtualDelegate ().OnEvent);

		if (!check (dv + dv))
			return 1;
		if (!check (dnv + dv))
			return 2;
		if (!check (dv + dnv))
			return 3;
		if (!check (dnv + dnv))
			return 4;

		return 0;
	}
Пример #52
0
	static int Main () {
		SimpleDelegate d = new SimpleDelegate (F);
		AsyncCallback ac = new AsyncCallback (async_callback);
		string state1 = "STATE1";
		string state2 = "STATE2";
		string state3 = "STATE3";
		string state4 = "STATE4";
		int fin = 0;
		
		IAsyncResult ar1 = d.BeginInvoke (1, ac, state1);
		IAsyncResult ar2 = d.BeginInvoke (2, ac, state2);
		IAsyncResult ar3 = d.BeginInvoke (3, ac, state3);
		IAsyncResult ar4 = d.BeginInvoke (4, ac, state4);
		
		int res = d.EndInvoke (ar1);

		Console.WriteLine ("Result = " + res);

		try {
			d.EndInvoke (ar1);
		} catch (InvalidOperationException) {
			Console.WriteLine ("cant execute EndInvoke twice ... OK");
		}

		ar1.AsyncWaitHandle.WaitOne ();
		if (ar1.IsCompleted) fin++;
		Console.WriteLine ("completed1: " + ar1.IsCompleted);
		ar2.AsyncWaitHandle.WaitOne ();
		if (ar2.IsCompleted) fin++;
		Console.WriteLine ("completed2: " + ar2.IsCompleted);
		ar3.AsyncWaitHandle.WaitOne ();
		if (ar3.IsCompleted) fin++;
		Console.WriteLine ("completed3: " + ar3.IsCompleted);
		ar4.AsyncWaitHandle.WaitOne ();		
		if (ar4.IsCompleted) fin++;
		Console.WriteLine ("completed4: " + ar4.IsCompleted);

		if (fin != 4)
			return 1;
		
		return 0;
	}
Пример #53
0
	public static int test_0_tests () {
		// Check that creation of delegates do not runs the class cctor
		DoIt doit = new DoIt (B.method);
		if (A.b_cctor_run)
			return 1;

		Tests test = new Tests ();
		SimpleDelegate d = new SimpleDelegate (F);
		SimpleDelegate d1 = new SimpleDelegate (test.VF);
		NotSimpleDelegate d2 = new NotSimpleDelegate (G);
		NotSimpleDelegate d3 = new NotSimpleDelegate (test.H);
		d ();
		d1 ();
		// we run G() and H() before and after using them as delegates
		// to be sure we don't corrupt them.
		G (2);
		test.H (3);
		Console.WriteLine (d2 (2));
		Console.WriteLine (d3 (3));
		G (2);
		test.H (3);

		if (d.Method.Name != "F")
			return 1;

		if (d3.Method == null)
			return 1;
		
		object [] args = {3};
		Console.WriteLine (d3.DynamicInvoke (args));

		AnotherDelegate d4 = new AnotherDelegate (puts);
		if (d4.Method == null)
			return 1;

		Console.WriteLine (d4.Method);
		Console.WriteLine (d4.Method.Name);
		Console.WriteLine (d4.Method.DeclaringType);
		
		return 0;
	}
Пример #54
0
	static int Main ()
	{
		SimpleDelegate d = new SimpleDelegate (F);
		AsyncCallback ac = new AsyncCallback (async_callback);
		string state1 = "STATE1";
		int res = 0;

		// Call delegate via ThreadPool and check that the exception is rethrown correctly
		IAsyncResult ar1 = d.BeginInvoke (1, ac, state1);

		while (cb_state == 0)
			Thread.Sleep (0);

		try {
			res = d.EndInvoke (ar1);
			Console.WriteLine ("NO EXCEPTION");
			return 1;
		} catch (NotImplementedException) {
			Console.WriteLine ("received exception ... OK");
		}

		return 0;
	}
Пример #55
0
	public static extern int mono_test_marshal_thread_attach (SimpleDelegate d);
Пример #56
0
 /// <summary>
 /// SafeThread constructor using SimpleDelegate object for anonymous methods, e.g.
 /// <code>
 ///     SafeThread safeThrd = new SafeThread((SimpleDelegate) delegate { dosomething(); });
 /// </code>
 /// </summary>
 /// <param name="sd"></param>
 public SafeThread(SimpleDelegate sd)
     : this()
 {
     _dlg = sd;
     _pts = new ParameterizedThreadStart(this.CallDelegate);
     ThreadObject = new Thread(_pts);
 }
Пример #57
0
	public static extern int mono_invoke_simple_delegate (SimpleDelegate d);
Пример #58
0
 public static GameComponent Wait(double seconds, SimpleDelegate then)
 {
     Effector ef = new Effector(0.0f);
     ef.Wait(seconds, then);
     return ef;
 }
Пример #59
0
 public ExitCommand(SimpleDelegate exit)
 {
     _exit = exit;
 }
Пример #60
0
 public FormSelection(SimpleDelegate extra)
 {
     InitializeComponent();
     this.extra = extra;
     this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
 }