/// <summary>开始跑商</summary> /// <param name="cid">马车主键</param> /// <param name="time">跑商时间</param> public void BusinssStart(Int64 user_id, Int64 cid, Int64 time) { try { var token = new CancellationTokenSource(); # if DEBUG //time = 30000; #endif Object obj = new BusinssObject { user_id = user_id, cid = cid, time = time }; Task.Factory.StartNew(m => { var t = m as BusinssObject; 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(t.time)); }, obj, token.Token) .ContinueWith((m, n) => { var bo = n as BusinssObject; if (bo == null) { token.Cancel(); return; } BUSINESS_END.GetInstance().CommandStart(bo.cid); //移除全局变量 var key = bo.GetKey(); bool r; Variable.CD.TryRemove(key, out r); token.Cancel(); }, obj, token.Token); }
/// <summary>BUSINESS_END单体模式</summary> public static BUSINESS_END GetInstance() { return(_objInstance ?? (_objInstance = new BUSINESS_END())); }