Пример #1
0
        /// <summary>
        /// 对页面进行更新
        /// </summary>
        public void Update(TimeSpan timeSpan)
        {
            ManagedThreadPool.QueueUserWorkItem(state =>
            {
                ArrayList arr        = state as ArrayList;
                IStaticPageItem item = (IStaticPageItem)arr[0];
                TimeSpan span        = (TimeSpan)arr[1];
                Thread.Sleep(span);

                item.Update();
            }, new ArrayList {
                this, timeSpan
            });
        }
Пример #2
0
        static void RunUpdate(DateTime updateTime)
        {
            lock (staticPageItems)
            {
                foreach (IStaticPageItem sti in staticPageItems)
                {
                    //需要生成才启动线程
                    if (sti.NeedUpdate(updateTime))
                    {
                        var thread = new Thread(state =>
                        {
                            if (state == null)
                            {
                                return;
                            }

                            ArrayList arr        = state as ArrayList;
                            IStaticPageItem item = arr[0] as IStaticPageItem;
                            DateTime time        = (DateTime)arr[1];

                            try
                            {
                                item.Update(time);
                            }
                            catch (Exception ex)
                            {
                                var exception = new StaticPageException("执行页面生成出现异常:" + ex.Message, ex);
                                if (OnError != null)
                                {
                                    try
                                    {
                                        OnError(exception);
                                    }
                                    catch { }
                                }
                            }
                        });

                        //启动线程
                        thread.Start(new ArrayList {
                            sti, updateTime
                        });
                    }
                }
            }
        }