Exemplo n.º 1
0
        private static void DogProc()
        {
            try
            {
                var logger = LogManager.GetLogger("beat");
                while (true)
                {
                    logger.Trace(string.Format("临时MT4池闲置:{0},会话MT4池闲置:{1}", _idel.Count, Poll.Keys.Count()));
                    Process proc    = Process.GetCurrentProcess();
                    MT4API  fetch   = null;
                    var     templst = new List <MT4API>();
                    var     count   = _idel.Count;
                    do
                    {
                        _idel.TryDequeue(out fetch);
                        if (fetch != null && !fetch.IsOutOfDate)
                        {
                            templst.Add(fetch);
                        }
                        else if (fetch != null)
                        {
                            fetch.Dispose();
                        }
                        count--;
                    } while (count > 0 && fetch != null);
                    foreach (var i in templst)
                    {
                        _idel.Enqueue(i);
                    }

                    templst.Clear();
                    foreach (var i in Poll.Keys)
                    {
                        fetch = null;
                        Poll._poll.TryRemove(i, out fetch);
                        if (fetch != null)
                        {
                            if (fetch.IsOutOfDate)
                            {
                                fetch.Dispose();
                            }
                            else
                            {
                                Poll._poll.TryAdd(i, fetch);
                            }
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
            catch (Exception e)
            {
                Logger errlogger = LogManager.GetLogger("clr_error");
                errlogger.Error("Dog线程遇到问题", e);
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 2
0
 internal override void LoadConfig(ConfigurationManager aConfig)
 {
     MT4Host        = aConfig.AppSettings["mt4_host"];
     MT4AdminID     = int.Parse(aConfig.AppSettings["mt4_user"]);
     MT4Passwd      = aConfig.AppSettings["mt4_passwd"];
     MT4Group       = aConfig.AppSettings["mt4_group"];
     MT4DemoHost    = aConfig.AppSettings["mt4demo_host"];
     MT4DemoAdminID = int.Parse(aConfig.AppSettings["mt4demo_user"]);
     MT4DemoPasswd  = aConfig.AppSettings["mt4demo_passwd"];
     MT4API.init(MT4Host, MT4AdminID, MT4Passwd);
 }
Exemplo n.º 3
0
        public static MT4Wrapper Fetch(int id)
        {
            MT4API fetch = null;

            _poll.TryRemove(id, out fetch);
            if (fetch == null || fetch.IsOutOfDate)
            {
                fetch = new MT4API(id);
            }
            else
            {
                fetch.LastPushTime = DateTime.Now;
            }
            return(fetch);
        }
Exemplo n.º 4
0
 public static MT4Wrapper New()
 {
     while (true)
     {
         MT4API fetch = null;
         do
         {
             _idel.TryDequeue(out fetch);
             if (fetch != null && !fetch.IsOutOfDate)
             {
                 return(fetch);
             }
         } while (fetch != null);
         var i = Interlocked.Increment(ref _taskid);
         return(new MT4API(i));
     }
 }