Ejemplo n.º 1
0
        public override ScheduledCallback Schedule(Action f, DateTime at)
        {
            var cb = new TimerScheduledCallback(f, at);

            lock (clean_up_mutex_)
                callbacks_.Add(cb);
            return(cb);
        }
Ejemplo n.º 2
0
        public IoServiceExecutor(long num_threads)
        {
            clean_up_cb_ = new TimerScheduledCallback(() => { clean_up(); }, DateTime.Now.AddSeconds(1));

            for (var i = 0; i < num_threads; i++)
            {
                var t = new Thread(ProcessQueue);
                threads.Add(t.ManagedThreadId, t);
                t.Start();
            }
        }
Ejemplo n.º 3
0
        private void clean_up()
        {
            lock (clean_up_mutex_)
            {
                try
                {
                    if (callbacks_.Count > 0)
                    {
                        TimerScheduledCallback[] temp = new TimerScheduledCallback[callbacks_.Count];
                        callbacks_.CopyTo(temp);

                        foreach (var item in temp)
                        {
                            callbacks_.Remove(item);
                        }
                    }
                }
                catch (Exception e)
                {
                    StdErrorOut.Instance.StdError("Executor.clean_up failed", e);
                }
            }
            clean_up_cb_.Reschedule(DateTime.Now.AddSeconds(1));
        }