Esempio n. 1
0
        /// <summary>
        /// 使用基本的委托定义
        /// </summary>
        public void NoUseFCL()
        {
            AddHandler   add   = Add;
            PrintHandler print = PrintString;

            print(add(12, 13).ToString());
        }
Esempio n. 2
0
        public void ResultIsEqualTo42()
        {
            var handler = new AddHandler();
            var result  = handler.Run(30, 12);

            Assert.AreEqual(result, 42);
        }
Esempio n. 3
0
        /// <summary> 获取战斗 </summary>
        /// <param name="userid">用户Id</param>
        /// <param name="rivalid">对手Id</param>
        /// <param name="type">战斗类型</param>
        /// <param name="hp">要调控血量 (爬塔、活动、连续战斗调用)</param>
        /// <param name="of">是否获取己方战斗Vo</param>
        /// <param name="po">是否推送己方战斗</param>
        /// <param name="or">是否获取对方战斗Vo</param>
        /// <param name="pr">是否推送对方战斗</param>
        /// <param name="rolehomeid">(武将宅类型时可用)要挑战武将宅id</param>
        /// <returns></returns>
        public Core.Entity.Fight GeFight(Int64 userid, Int64 rivalid, FightType type, Int64 hp = 0, bool of = false, bool po = false, bool or = false, bool pr = false, int rolehomeid = 0)
        {
            var handler  = new AddHandler(new FightCommon().GeFight);
            var result   = handler.BeginInvoke(userid, rivalid, type, hp, of, po, or, pr, rolehomeid, null, null);
            var handler1 = (AddHandler)((AsyncResult)result).AsyncDelegate;

            return(handler1.EndInvoke(result));
        }
        /// <summary>
        /// 异步回调方法
        /// 用回调函数,当调用结束时会自动调用回调函数,
        /// 解决了为等待调用结果,而让线程依旧被阻塞的局面。
        /// </summary>
        public void Asynchronous_Callback_Method()
        {
            Console.WriteLine("===== 异步回调 AsyncInvokeTest =====");
            AddHandler   handler = new AddHandler(Add);           //异步操作接口(注意BeginInvoke方法的不同!)
            IAsyncResult result  = handler.BeginInvoke(1, 2, new AsyncCallback(CallBackMethod), "AsycState:OK");

            Console.WriteLine("继续做别的事情。。。");
        }
Esempio n. 5
0
        public CCallback()
        {
            Console.WriteLine("===== 异步回调 AsyncInvokeTest =====");
            AddHandler handler = new AddHandler(CAdd.Add);
            //异步操作接口(注意BeginInvoke方法的不同!)
            IAsyncResult result = handler.BeginInvoke(1, 2, new AsyncCallback(CallbackFunc), "AsycState:OK");

            Console.WriteLine("继续做别的事情。。。");
        }
Esempio n. 6
0
        public CSyncInvoke()
        {
            Console.WriteLine("===== 同步调用 Sync Invoke Test =====");
            AddHandler handler = new AddHandler(CAdd.Add);
            int        result  = handler(1, 2); //等价于handler.Invoke(1, 2);

            Console.WriteLine("继续做别的事情。。。");
            Console.WriteLine(result);
        }
Esempio n. 7
0
 public Octree(T space, AddHandler addHandler, RemoveHandler removeHandler, SearchHandler searchHandler, SetRootHandler setRootHandler, RemoveAllHandler removeAllHandler)
 {
     this.space = space;
     this.AddHandlerCallback       = addHandler;
     this.RemoveHandlerCallback    = removeHandler;
     this.SearchHandlerCallback    = searchHandler;
     this.SetRootHandlerCallback   = setRootHandler;
     this.RemoveAllHandlerCallback = removeAllHandler;
 }
        static ObjectManager()
        {
            mAddHandler = new AddHandler(addImpl);
            UnmanagedObjectManager_setAdd(mAddHandler);
            mRemoveHandler = new RemoveHandler(removeImpl);
            UnmanagedObjectManager_setRemove(mRemoveHandler);

            mObjectMap = new Dictionary<IntPtr, Holder>();
        }
Esempio n. 9
0
 private void AddWordButton_Click(object sender, EventArgs e)
 {
     AddWord();
     if (AddedWords.Count == 0)
     {
         return;
     }
     AddHandler?.Invoke(this, null);
     Close();
 }
Esempio n. 10
0
        static void 回调函数(IAsyncResult result)
        {
            //result 是“加法类.Add()方法”的返回值
            //AsyncResult 是IAsyncResult接口的一个实现类,空间:System.Runtime.Remoting.Messaging
            //AsyncDelegate 属性可以强制转换为用户定义的委托的实际类。
            AddHandler handler = (AddHandler)((AsyncResult)result).AsyncDelegate;

            handler.EndInvoke(result);
            Console.WriteLine(result.AsyncState);
        }
    static void callback(IAsyncResult result)
    {
        //result 是“deposit_status_sync_AsyncMethod()方法”的返回值
        //AsyncResult 是IAsyncResult接口的一个实现类,引用空间:System.Runtime.Remoting.Messaging
        //AsyncDelegate 属性可以强制转换为用户定义的委托的实际类。
        AddHandler handler    = (AddHandler)((AsyncResult)result).AsyncDelegate;
        LogClass   notifylogs = (LogClass)result.AsyncState;

        notifylogs.WriteLogFile("日志——异步委托执行结果是 :" + handler.EndInvoke(result), LOGending: true);
    }
Esempio n. 12
0
        static void AsyncCallBackFun(IAsyncResult result)
        {
            // result 是 "ClassAdd 类的 Add() 方法" 的返回值
            // AsyncResult 是 IAsyncResult 接口的一个实现类,命名空间:System.Runtime.Remoting.Messaging
            // AsyncDelegate 属性可以强制转换为用户自定义的委托实现类
            AddHandler addHandler = (AddHandler)((AsyncResult)result).AsyncDelegate;

            Console.WriteLine(addHandler.EndInvoke(result));
            Console.WriteLine(result.AsyncState);
        }
        private void CallBackMethod(IAsyncResult ar)
        {
            //result 是“加法类.Add()方法”的返回值
            //AsyncResult 是IAsyncResult接口的一个实现类,空间:System.Runtime.Remoting.Messaging
            //AsyncDelegate 属性可以强制转换为用户定义的委托的实际类。
            AddHandler handler = (AddHandler)((AsyncResult)ar).AsyncDelegate;

            Console.WriteLine(handler.EndInvoke(ar));
            Console.WriteLine(ar.AsyncState);
        }
Esempio n. 14
0
        public static void Main_S()
        {
            Console.WriteLine("===== 同步调用 SyncInvokeTest =====");
            AddHandler handler = new AddHandler(AddClass.Add);
            int        result  = handler.Invoke(1, 2, 3);

            Console.WriteLine("继续做别的事情。。。");

            Console.WriteLine(result);
        }
        /// <summary>
        /// 同步方法
        /// </summary>
        public void Synchronized_Method()
        {
            Console.WriteLine("===== 同步调用 SyncInvokeTest =====");
            AddHandler handler = new AddHandler(Add);

            //invoke后阻塞主进程,直到handler执行完毕
            int result = handler.Invoke(1, 2);

            Console.WriteLine("继续做别的事情。。。");
            Console.WriteLine(result);
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            Console.WriteLine("===== 异步回调测试 =====");
            AddHandler addHandler = new AddHandler(ClassAdd.Add);

            // 异步操作接口
            IAsyncResult result = addHandler.BeginInvoke(8000, 8000, new AsyncCallback(AsyncCallBackFun), "AsyncState: OK");

            Console.WriteLine("我继续干点别的...");
            Console.ReadLine();
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            Console.WriteLine("===== 异步回调 AsyncInvokeTest =====");
            AddHandler handler = new AddHandler(AddClass.Add);

            //异步操作接口(注意BeginInvoke方法的不同!)
            IAsyncResult result = handler.BeginInvoke(1, 2, 3, new AsyncCallback(CallbackFunc), "AsycState:OK");

            Console.WriteLine("------继续做别的事情。。。--------");
            Console.ReadKey();
        }
Esempio n. 18
0
        public void AsynTest()
        {
            Console.WriteLine("===== 异步回调 AsyncInvokeTest =====");
            AddHandler handler = new AddHandler(AddClass.Add);

            //异步操作接口(注意BeginInvoke方法的不同!)
            IAsyncResult result = handler.BeginInvoke(1, 2, 3, new AsyncCallback(CallbackFunc), "AsycState:OK");

            Console.WriteLine("------继续做别的事情。。。--------");
            return;
        }
Esempio n. 19
0
        public HttpResponseMessage Add(ReportComponentDto reportDto)
        {
            var handler  = new AddHandler();
            var response = handler.Handle(reportDto);

            if (handler.Errors == null || handler.Errors.Count < 1)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, response.ReportComponentDtos[0]));
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest, handler.Errors));
        }
Esempio n. 20
0
        void test_1()
        {
            AddHandler handler = new AddHandler(adder);
            //异步操作接口(注意BeginInvoke方法的不同!)
            IAsyncResult result = handler.BeginInvoke(1, 2, new AsyncCallback(cbfunc), "AsycState:OK");

            Console.WriteLine("继续做别的事情。。。");
            //Thread.Sleep(10000);
            OutputLine("end");
            //Console.ReadKey();
        }
        /// <summary>
        /// 异步方法
        /// 主线程并没有等待,而是直接向下运行了。但是问题依然存在,
        /// 当主线程运行到EndInvoke时,如果这时调用没有结束(这种情况很可能出现),
        /// 这时为了等待调用结果,线程依旧会被阻塞。
        /// </summary>
        public void Asynchronous_Method()
        {
            Console.WriteLine("===== 异步调用 AsyncInvokeTest =====");
            AddHandler handler = new AddHandler(Add);
            //IAsyncResult: 异步操作接口(interface)
            //BeginInvoke: 委托(delegate)的一个异步方法的开始
            IAsyncResult result = handler.BeginInvoke(1, 2, null, null);

            Console.WriteLine("继续做别的事情。。。");
            //异步操作返回
            Console.WriteLine(handler.EndInvoke(result));
        }
Esempio n. 22
0
        /*运行结果:
         * ===== 异步调用 AsyncInvokeTest =====
         * 继续做别的事情。。。
         * 开始计算:1+2
         * 计算完成!
         * 3
         */

        #endregion

        #region 异步回调

        public static void AsynchronismcallbackFun()
        {
            Console.WriteLine("===== 异步回调 AsyncInvokeTest =====");
            //1.先用委托 挂载一个要执行的函数
            AddHandler handler = new AddHandler(Additive.Add);

            //异步操作接口(注意BeginInvoke方法的不同!)
            //2.BeginInvoke开始异步调用,【委托定义的参数,方法执行完毕之后回调的函数,状态】返回一个异步操作的状态
            IAsyncResult result = handler.BeginInvoke(1, 2, new AsyncCallback(CallbackFuction), "AsycState:OK");

            //这里的好处就是不用等待结果的返回 代码还能够继续往下执行
            Console.WriteLine("继续做别的事情。。。");
            Console.ReadKey();
        }
Esempio n. 23
0
        public async Task Add_returns_with_success_for_valid_path()
        {
            var mockFileSystem = new MockFileSystem(
                new Dictionary <string, MockFileData> {
                { "output.txt", new MockFileData("my data") }
            }
                );

            var addHandler = new AddHandler(mockFileSystem);
            await addHandler.Handle(new AddOptions()
            {
                Path = "output.txt"
            }, CancellationToken.None);
        }
Esempio n. 24
0
    static AssetLocker()
    {
        EditorApplication.update   += Update;
        Selection.selectionChanged += OnSelectionChanged;

        add       = new AddHandler();
        isTracked = new IsTrackedHandler();
        lck       = new LockHandler();
        unlock    = new UnlockHandler();
        isLocked  = new IsLockedHandler();
        getInfo   = new GetInfoHandler();

        lockedInfo = new Dictionary <string, Asset>();
        Debug.Log("AssetLocker initialized");
    }
Esempio n. 25
0
        public static void Main_S()
        {
            Console.WriteLine("===== 异步调用 AsyncInvokeTest =====");
            AddHandler handler = new AddHandler(AddClass.Jian);

            //IAsyncResult: 异步操作接口(interface)
            //BeginInvoke: 委托(delegate)的一个异步方法的开始
            IAsyncResult result = handler.BeginInvoke(1, 2, 3, null, null);

            Console.WriteLine("------继续做别的事情。。。\n");

            //异步操作返回
            Console.WriteLine(handler.EndInvoke(result));
            return;
        }
Esempio n. 26
0
        public void cbfunc(IAsyncResult result)
        {
            //result 是“加法类.Add()方法”的返回值
            //AsyncResult 是IAsyncResult接口的一个实现类,空间:System.Runtime.Remoting.Messaging
            //AsyncDelegate 属性可以强制转换为用户定义的委托的实际类。
            AddHandler handler = (AddHandler)((AsyncResult)result).AsyncDelegate;
            //Console.WriteLine(handler.EndInvoke(result));
            //Console.WriteLine(result.AsyncState);
            Action ac = () =>
            {
                OutputLine("hh is " + handler.EndInvoke(result).ToString());
                OutputLine((string)result.AsyncState);
            };

            Invoke(ac);
        }
Esempio n. 27
0
        public static void T()
        {
            AddHandler   add   = Add;
            PrintHandler print = Print;

            print(add(1, 2).ToString());

            Func <int, int, int> addFunc = Add;
            // Action has not return value
            Action <string> printAc = Print;

            printAc(addFunc(3, 4).ToString());

            AddFunc = Add;
            printAc(AddFunc(5, 6).ToString());
        }
Esempio n. 28
0
        static void CallbackFuction(IAsyncResult result)
        {
            //result 是“加法类.Add()方法”的返回值

            //AsyncResult 是IAsyncResult接口的一个实现类,引用空间:System.Runtime.Remoting.Messaging
            //AsyncDelegate 属性可以强制转换为用户定义的委托的实际类。

            AddHandler handler = (AddHandler)((AsyncResult)result).AsyncDelegate;

            //MethodInfo m = handler.Method;
            //Console.WriteLine(m.Name);
            //ParameterInfo[] par = m.GetParameters();

            Console.WriteLine(handler.EndInvoke(result)); //结束异步返回计算的结果
            Console.WriteLine(result.AsyncState);         //异步结束后的状态
        }
Esempio n. 29
0
        public static void SynchronizationFun()
        {
            Console.WriteLine("===== 同步调用 SyncInvokeTest =====");

            AddHandler handler = new AddHandler(Additive.Add);
            //同步的效果就是当前的线程必须阻塞,得到result结果的返回,在winform下就会造成界面的假死

            //“委托人”去Invoke
            int result = handler.Invoke(1, 2);

            //直到委托执行的方法完全完成 下面才会执行
            Console.WriteLine("继续做别的事情。。。");
            Console.WriteLine(result);

            Console.ReadKey();
        }
Esempio n. 30
0
        delegate bool CompareReult(TempClass data); //回傳值

        /// <summary>
        /// 傳統的委派,並執行函式
        /// </summary>
        public void OrigineDelegate()
        {
            AddHandler   addInt     = AddInt;
            PrintConsole print      = OutputString;
            CompareReult intCompare = IsEqualInt;

            print(addInt(10, 25).ToString());
            print(IsEqualInt(new TempClass()
            {
                X = 20, Y = 20
            }).ToString());
            print(IsEqualInt(new TempClass()
            {
                X = 20, Y = 15
            }).ToString());
            //輸出結果 35 , true , false
        }
Esempio n. 31
0
        public async Task Add_throws_exception_with_invalid_path()
        {
            var mockFileSystem = new MockFileSystem(
                new Dictionary <string, MockFileData> {
                { "output.txt", new MockFileData("my data") }
            }
                );

            var addHandler = new AddHandler(mockFileSystem);

            await Should.ThrowAsync <PathForAddNotFoundException>(async() =>
            {
                await addHandler.Handle(new AddOptions()
                {
                    Path = "notfound.txt"
                }, CancellationToken.None);
            });
        }
Esempio n. 32
0
        private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = null;
            AddHandler add = new AddHandler((a, b) =>
            {
                thread = Thread.CurrentThread;
                System.Threading.Thread.Sleep(10000);
                return a + b;
            });
            var ar = add.BeginInvoke(1, 2, iar => { }, add);

            if (!ar.AsyncWaitHandle.WaitOne(1000, true))
            {
                thread.Abort();
                //ar.AsyncWaitHandle.Close();
                textBox1.Text = "timeout!";
            }
            else
            {
                textBox1.Text = add.EndInvoke(ar).ToString();
                ar.AsyncWaitHandle.Close();
            }
        }