Ejemplo n.º 1
0
 /// <summary>创建生活技能修炼线程</summary>
 public void ThreadingUpgrade(Int64 user_id, Int64 rid, Int64 costtime)
 {
     try
     {
         var token = new CancellationTokenSource();
         //# if DEBUG
         //                costtime = 5000;
         //#endif
         Object obj = new LifeObject {
             user_id = user_id, rid = rid
         };
         Task.Factory.StartNew(m =>
         {
             var t = m as LifeObject;
             if (t == null)
             {
                 return;
             }
             var key = t.GetKey();
             Variable.CD.AddOrUpdate(key, false, (k, v) => false);
             SpinWait.SpinUntil(() =>
             {
                 var b = Convert.ToBoolean(Variable.CD[key]);
                 return(b);
             }, Convert.ToInt32(costtime));
         }, obj, token.Token)
         .ContinueWith((m, n) =>
         {
             var lo = n as LifeObject;
             if (lo == null)
             {
                 token.Cancel(); return;
             }
             SKILL_LIFE_PUSH.GetInstance().LifePush(lo.user_id, lo.rid);
             //移除全局变量
             var key = lo.GetKey();
             bool r;
             Variable.CD.TryRemove(key, out r);
             token.Cancel();
         }, obj, token.Token);
     }
     catch (Exception ex)
     {
         XTrace.WriteException(ex);
     }
 }
Ejemplo n.º 2
0
 /// <summary> SKILL_LIFE_PUSH单体模式 </summary>
 public static SKILL_LIFE_PUSH GetInstance()
 {
     return(ObjInstance ?? (ObjInstance = new SKILL_LIFE_PUSH()));
 }