예제 #1
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("继续做别的事情。。。");
        }
예제 #3
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("继续做别的事情。。。");
        }
예제 #4
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();
        }
예제 #5
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();
        }
예제 #6
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;
        }
예제 #7
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();
        }
        /// <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));
        }
예제 #9
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();
        }
예제 #10
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;
        }
예제 #11
0
        /*运行结果:
         * ===== 同步调用 SyncInvokeTest =====
         * 开始计算:1+2
         * 计算完成!
         * 继续做别的事情。。。
         * 3
         */
        #endregion

        #region 异步调用
        public static void AsynchronousMain()
        {
            Console.WriteLine("===== 异步调用 AsyncInvokeTest =====");
            //你会发现这里的ManagedThreadId和执行 Add方法的 线程ID不一致的,我们使用异步的方式 简洁的操作了线程
            Console.WriteLine("AsynchronousMain当前线程唯一表示:" + Thread.CurrentThread.ManagedThreadId);

            AddHandler handler = new AddHandler(Additive.Add);

            //IAsyncResult: 异步操作接口(interface)
            //BeginInvoke: 委托(delegate)的一个异步方法的开始
            //BeginInvoke开始一个异步操作

            //委托人:开始BeginInvoke
            IAsyncResult result = handler.BeginInvoke(1, 2, null, null);

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


            //委托人:监控异步操作返回
            Console.WriteLine(handler.EndInvoke(result));
            Console.ReadKey();
        }
예제 #12
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();
            }
        }
예제 #13
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();
            }
        }
예제 #14
0
        static void Main(string[] args)
        {
            string  haha  = "1.2346";
            string  xixi  = "1.2346";
            decimal dhaha = decimal.Parse(haha);
            decimal dxixi = decimal.Parse(xixi);

            if (dhaha == dxixi)
            {
                Console.WriteLine("不得不服");
            }
            Dictionary <string, int> dir = new Dictionary <string, int>();

            dir.Add("1", 1);
            dir.Add("3", 3);
            dir.Add("2", 2);

            Dictionary <string, 加法类> PriceReceive = new Dictionary <string, 加法类>();

            PriceReceive.Add("RETUR", new 加法类());
            PriceReceive.Add("SAXO", new 加法类());
            PriceReceive.Add("SP", new 加法类());
            Dictionary <string, 加法类> PriceReceive1 = new Dictionary <string, 加法类>();

            PriceReceive1.Add("SAXO", new 加法类());
            PriceReceive1.Add("RETUR", new 加法类());
            PriceReceive1.Add("SP", new 加法类());

            //Hashtable PriceReceive2 = new Hashtable();
            //PriceReceive2 = PriceReceive;

            foreach (string item in PriceReceive.Keys)
            {
                Console.WriteLine(item);
            }
            PriceReceive = new Dictionary <string, 加法类>();
            foreach (string item in PriceReceive1.Keys)
            {
                PriceReceive.Add(item, PriceReceive1[item]);
            }

            foreach (string item in PriceReceive.Keys)
            {
                Console.WriteLine(item);
            }



            Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++");


            string t1 = string.Empty;

            if (t1 == "")
            {
                Console.WriteLine("123");
            }
            Console.WriteLine(t1.Length);
            加法类 te = new 加法类();

            te.name = "123";
            加法类 se = te;

            te.name = "345";
            Console.WriteLine(se.name);

            decimal f = 20;
            decimal t = Convert.ToDecimal(f / 100);

            Console.WriteLine(t);
            Console.WriteLine(DateTime.Now.Day);
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));

            string        AddProductList  = "AUDUSD_";
            List <string> lstTradeProduct = new List <string>(AddProductList.Split('_'));

            for (int i = 0; i < lstTradeProduct.Count; i++)
            {
                Console.WriteLine(lstTradeProduct[i] + "___");
            }

            if (DateTime.Now.Hour == 15)
            {
                Console.WriteLine("你想不到吧");
            }
            string test = "/fefg123";

            Console.WriteLine(test.ToUpper());
            //Console.WriteLine("===== 同步调用 SyncInvokeTest =====");
            //AddHandler handler = new AddHandler(加法类.Add);
            //int result = handler(1, 2);
            //Console.WriteLine("继续做别的事情。。。");
            //Console.WriteLine(result);
            //Console.ReadKey();

            //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));
            //Console.ReadKey();

            Console.WriteLine("===== 异步回调 AsyncInvokeTest =====");
            AddHandler handler = new AddHandler(加法类.Add);
            //异步操作接口(注意BeginInvoke方法的不同!)
            IAsyncResult result = handler.BeginInvoke(1, 2, ar => handler.EndInvoke(ar), "AsycState:OK");

            Console.WriteLine("继续做别的事情。。。");
            Console.ReadKey();
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        SortedList <string, string> pay_result = new SortedList <string, string>();
        LogClass notifylogs = new LogClass();

        notifylogs.WriteLogFile("异步入口:开始获取外部请求过来的数据:" + "POST请求过来的数据:" + Request.Form.ToString() + "----------GET请求过来的数据:" + Request.QueryString.ToString());
        for (int i = 0; i < Request.Form.Count; i++)
        {
            pay_result.Add(Request.Form.Keys[i].ToString(), Request.Form[i].ToString());
        }
        try
        {
            bool Check_SignMsg_result = com.sinapay.weibopayapi.Check_SignMsg(pay_result, pay_result["sign_type"], pay_result["sign"], pay_result["_input_charset"], notifylogs);
            if (Check_SignMsg_result)
            {
                try
                {
                    notifylogs.WriteLogFile("日志——验证新浪来源签名成功:新浪异步推送过来的报文是:" + new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(pay_result));
                    switch (pay_result["notify_type"])
                    {
                    case "trade_status_sync":    //交易结果通知
                        //1.此处将pay_result LIST插入InsertInto trade_status_sync对应的数据库。无sql代码示例,以商户数据库为准。其他case雷同
                        //...sql...!
                        //2.更新数据以后做异步委托,必须在异步委托中处理自身的业务,不允许在此处做业务处理。正常收到数据后必须5秒内响应success。超时新浪视为推送失败,进入重试机制
                        AddHandler   trade_status_sync_AsyncDelegate = new AddHandler(trade_status_sync_AsyncMethod);
                        IAsyncResult iAsyncRslt = trade_status_sync_AsyncDelegate.BeginInvoke(pay_result, notifylogs, new AsyncCallback(callback), notifylogs);
                        break;

                    case "refund_status_sync":    //交易退款结果通知
                    case "deposit_status_sync":   //充值结果通知
                        AddHandler   deposit_status_synchandler = new AddHandler(deposit_status_sync_AsyncMethod);
                        IAsyncResult result = deposit_status_synchandler.BeginInvoke(pay_result, notifylogs, new AsyncCallback(callback), notifylogs);
                        break;

                    case "withdraw_status_sync":    //出款结果通知
                        AddHandler   withdraw_status_synchandler = new AddHandler(withdraw_status_syncAsyncMethod);
                        IAsyncResult withdraw_status_sync_result = withdraw_status_synchandler.BeginInvoke(pay_result, notifylogs, new AsyncCallback(callback), notifylogs);
                        break;

                    case "batch_trade_status_sync": //批量交易结果通知
                    case "audit_status_sync":       //审核结果通知
                        AddHandler   audit_status_synchandler = new AddHandler(audit_status_syncAsyncMethod);
                        IAsyncResult audit_status_sync_result = audit_status_synchandler.BeginInvoke(pay_result, notifylogs, new AsyncCallback(callback), notifylogs);
                        break;

                    case "bid_status_sync":    //标的状态通知
                        break;

                    case "mig_set_pay_password":    //设置支付密码(会员信息综合通知)
                        break;

                    case "mig_binding_card":    //绑定银行卡(会员信息综合通知)
                        break;

                    case "mig_change_card":    //换绑银行卡(会员信息综合通知)
                        break;

                    case "mig_unbind_card":    //解绑银行卡(会员信息综合通知)
                        break;

                    case "mig_apply_withhold":    //申请委托扣款(会员信息综合通知)
                        break;

                    case "mig_modify_withhold":    //修改委托扣款(会员信息综合通知)
                        break;

                    case "mig_cancel_withhold":    //取消委托扣款(会员信息综合通知)
                        break;
                    }
                    Response.Write("success");
                }
                catch (Exception exx)
                {   //如果插入数据库失败,请勿响应success,新浪会尝试最多七次,重发数据.中间只要响应success就不会再次重发数据
                    //SINA异步重试推送间隔 [[2, 10, 10, 60, 120, 360, 900]] 单位(分钟)
                    Response.Write("updata sql fail");
                    notifylogs.WriteLogFile(exx.ToString());
                }
            }
            else
            {   //校验签名验证数据失败,或KEY不正确,或数据在传输途中被篡改
                Response.Write("sign error!");
            }
        }
        catch (Exception exx)
        {//不正当来源数据。
            Response.Write("error!");
            notifylogs.WriteLogFile(exx.ToString(), LOGending: true);
        }
    }