public static void CallBack(DelegateCallback delegateCallback) { Console.WriteLine("Mời bạn nhập thông báo: "); var mes = Console.ReadLine(); delegateCallback(mes); //showMes(mes);//Gọi theo kiểu C#1 }
public void Invoke <J, K, M>(J outArg1, K outArg2, M outArg3) { DelegateCallback <J, K, M> action = mCallback as DelegateCallback <J, K, M>; if (action != null) { action.Invoke(outArg1, outArg2, outArg3); } Release(); }
public void Invoke <J>(J outArg1) { DelegateCallback <J> action = mCallback as DelegateCallback <J>; if (action != null) { action.Invoke(outArg1); } Release(); }
public void Invoke() { DelegateCallback action = mCallback as DelegateCallback; if (action != null) { action.Invoke(); } Release(); }
public void Invoke <J, K, M>(J outArg1, K outArg2, M outArg3) { DelegateCallback <J, K, M> action = mCallback as DelegateCallback <J, K, M>; if (action != null) { action.Invoke(outArg1, outArg2, outArg3); } else { LogError(mCallback.GetType(), typeof(J), typeof(K), typeof(M)); } Release(); }
//protected bool IsReady = false; //private new bool IsDisposed = false; public PluginForm() { BorderWidth = (this.Width - this.ClientSize.Width) / 2; TitlebarHeight = this.Height - this.ClientSize.Height - BorderWidth * 2; CloseWindow += CloseWindow_Delegate; ShowWindow += ShowWindow_Delegate; HideWindow += HideWindow_Delegate; ActivateWindow += ActivateWindow_Delegate; ShowWindow += delegate() { ActivateWindow_Delegate(); }; Disposed += new EventHandler(PluginForm_Disposed); }
public void Invoke() { DelegateCallback action = mCallback as DelegateCallback; if (action != null) { action.Invoke(); } else { LogError(mCallback.GetType()); } Release(); }
public void Invoke <J>(J outArg1) { DelegateCallback <J> action = mCallback as DelegateCallback <J>; if (action != null) { action.Invoke(outArg1); } else { LogError(mCallback.GetType(), typeof(J)); } Release(); }
//protected bool IsReady = false; //private new bool IsDisposed = false; public PluginForm() { BorderWidth = (this.Width-this.ClientSize.Width)/2; TitlebarHeight = this.Height - this.ClientSize.Height - BorderWidth * 2; CloseWindow += CloseWindow_Delegate; ShowWindow += ShowWindow_Delegate; HideWindow += HideWindow_Delegate; ActivateWindow += ActivateWindow_Delegate; ShowWindow += delegate() { ActivateWindow_Delegate(); }; Disposed += new EventHandler(PluginForm_Disposed); }
private void Start() { for (int i = 0; i < 2; i++) { if (i < 1) { DelegateCallbackIns = Service1.Callback1; } else { DelegateCallbackIns = Service1.Callback2; } CallbackMethod(2, 8, DelegateCallbackIns); } }
// Use this for initialization void Start() { for (int i = 0; i < 10000; i++) { inputNames.Add("Input-" + i.ToString()); outputNames.Add("Output-" + i.ToString()); } mDel1 = TestCallback; mDel2 = TestCallback; mDel3 = OnModelLoaded; testClass.go = gameObject; callNum = 0; threadStart = false; mThread = new Thread(ThreadUpdate); mThread.Start(); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.GetEncoding("UTF-8"); #region Phần 1: Khởi tạo null Console.WriteLine("======Phần 1: Khởi tạo null======="); ShowMessage showMessage = null; //Khởi tạo delegate = null showMessage = Info1; //trỏ đến phương thức //Sử dụng delegate //Info1("Xin chào các bạn đang học delegate C#2"); Ở C#1 gọi phương thức thẳng showMessage(" Xin chào các bạn đang học delegate C#2"); showMessage?.Invoke(" Xin chào các bạn đang học delegate C#2");//? Kiểm tra xem delegate có null hay không thì mới tham chiếu. #endregion #region Phần 2: Khởi tạo Console.WriteLine("======Phần 2: Khởi tạo======="); ShowMessage showMessage2 = new ShowMessage(Info1);//Tham chiếu đến phương thức info1 showMessage2("Chào các bạn .NET học Delegate"); #endregion #region Phần 3: Multicast Delegate Console.WriteLine("======Phần 3: Multicast Delegate======="); ShowMessage showMessage3 = new ShowMessage(Info1); ShowMessage showMessage4 = new ShowMessage(Info2); ShowMessage Multicast = showMessage3 + showMessage4; Multicast += showMessage3; Multicast += showMessage4; Multicast("Chào mừng học được Multicast rồi"); Console.WriteLine("=====Trừ trong Delegate======="); Multicast = Multicast - showMessage3;//Loại bỏ bớt 1 phương trong delegate dùng dấu trừ Multicast -= showMessage3; Multicast("Chào mừng học được Multicast rồi"); #endregion #region Phần 4: Delegate Callback Method Console.WriteLine("======Phần 4: Delegate Callback Method======="); DelegateCallback delegateCallback = new DelegateCallback(showMes); CallBack(delegateCallback);//Gọi phương thức truyền vào 1 delegate đang trỏ đến 1 phương thức khác #endregion }
protected void MakeDelegate(DelegateCallback callback) { DelegateCallback delegateCallback = new DelegateCallback(callback); try { if (Handle != IntPtr.Zero) { if (InvokeRequired) { Invoke(delegateCallback); } else { delegateCallback.Invoke(); } } } catch (Exception err) { Exceptions.LogOnly(err); } }
private void TestDeCall(DelegateCallback <object, int, string, object, int, string> del, object j, int k, string m, object t, int u, string v) { del.Invoke(j, k, m, t, u, v); }
private void TestDeCall(DelegateCallback <object, int, string, int> del, object j, int k, string t, int u) { del.Invoke(j, k, t, u); }
private void TestDe <J, K, M, T, U, V>(DelegateCallback <J, K, M, T, U, V> del, J j, K k, M m, T t, U u, V v) { del.Invoke(j, k, m, t, u, v); }
private void TestDe <J, K, T, U>(DelegateCallback <J, K, T, U> del, J j, K k, T t, U u) { del.Invoke(j, k, t, u); }
public static extern void SetOnUnityPluginUnload(DelegateCallback callback);
public void CallbackMethod(int a, int b, DelegateCallback cllbck) { cllbck(a, b); }