• C#委托实现系统回调


    在C#中,系统回调感觉都是用委托实现的(实际委托就应该称为OO化的函数回调)

    比较典型的是三个

    1.cache

    CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(onRemove);

                    HttpContext.Current.Cache.Insert(CacheKey, CacheInfo, null,
                        System.DateTime.Now.AddSeconds(300),
                        System.Web.Caching.Cache.NoSlidingExpiration,
                        System.Web.Caching.CacheItemPriority.Default,
                        callBack);

            /// <summary>
            /// cache失效时触发
            /// </summary>
            /// <param name="IdentifyCode"></param>
            /// <param name="Info"></param>
            /// <param name="reason"></param>
            private static void onRemove(string IdentifyCode, object CacheInfo, CacheItemRemovedReason reason)
            {

            }

    2.Timer

            System.Timers.Timer SSOTimer = new System.Timers.Timer(10000);
            SSOTimer.Elapsed += new System.Timers.ElapsedEventHandler(SSOTimer_Elapsed);
            SSOTimer.AutoReset = true;
            SSOTimer.Enabled = true;

        /// <summary>
        /// 达到间隔时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SSOTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {

        }

    3.异步传输

    AsyncCallback acb = new AsyncCallback(WebCallback);
    IAsyncResult IAR = BeginByte(WholeParameters, acb, null);
    Byte[] ReturnValue = EndByte(IAR);

            /// <summary>
            /// 数据传输完成调用此方法
            /// </summary>
            /// <param name="IAR"></param>

            protected void WebCallback(IAsyncResult IAR)
            {
                //Byte[] ReturnValue = EndPublicObjectHashtableByte(IAR);
            }

  • 相关阅读:
    Codeforces Round #632 (Div. 2)
    Codeforces Round #630 (Div. 2)
    多项式全家桶
    Educational Codeforces Round 84 (Rated for Div. 2)
    【cf1186E】E. Vus the Cossack and a Field(找规律+递归)
    [CF847B] Preparing for Merge Sort
    [CF858D] Polycarp's phone book
    [CF911D] Inversion Counting
    [CF938C] Constructing Tests
    [CF960C] Subsequence Counting
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/1299655.html
Copyright © 2020-2023  润新知