Exemplo n.º 1
0
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }
            PlayBackArgs args     = (PlayBackArgs)e.Argument;
            DateTime     prevtime = DateTime.MinValue;
            DateTime     playto   = h.NextTickTime;

            while (h.NextTickTime != HistSim.ENDSIM)
            {
                if (CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                // if we're past user specified DayStart, use user-specified delay otherwise no delay
                int delay = (h.NextTickTime.TimeOfDay >= args.DayStart.TimeOfDay) ?
                            (int)h.NextTickTime.Subtract(prevtime).TotalMilliseconds *args.DELAYSCALE : 0;
                if (prevtime != DateTime.MinValue)                     // if it's not first time doing this
                {
                    System.Threading.Thread.CurrentThread.Join(delay); // wait realistic time
                }
                prevtime = new DateTime(h.NextTickTime.Ticks);         // save last time mark
                double progress = 100.0 * ((h.TickCount + h.IndexCount) / (double)h.ApproxTotalTicks);
                ReportProgress((int)progress);                         // report progress
                h.PlayTo(h.NextTickTime);                              // this will throw tick/idx events and get next time mark
            }
            base.OnDoWork(e);
        }
Exemplo n.º 2
0
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            if (h == null)
            {
                return;
            }
            if (e.Cancel)
            {
                return;
            }
            PlayBackArgs args     = (PlayBackArgs)e.Argument;
            long         prevtime = 0;

            // play first tick
            h.PlayTo(0);
            do
            {
                // if cancel was requested, quit
                if (CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                // play first tick
                long next = h.NextTickTime;

                h.PlayTo(next);
                // adjust delay, based on user's setting of 'speed'
                var mindelay = 1000 * args.DELAYSCALE;
                int delay    = Util.FTDIFF((int)prevtime, (int)next) * mindelay;
                if (delay < 0)
                {
                    delay = mindelay;
                }
                // if not first tick, wait realistic time between ticks
                if (delay != 0)
                {
                    System.Threading.Thread.CurrentThread.Join(delay);
                }
                // save time for calculating next day
                prevtime = next;
                // calculate progress
                double progress     = 100.0 * (h.TicksProcessed / (double)h.TicksPresent);
                int    thisprogress = (int)progress;
                // report progress
                if (thisprogress > lastprogress)
                {
                    ReportProgress(thisprogress);
                    lastprogress = thisprogress;
                }
            }while (h.NextTickTime != MultiSimImpl.ENDSIM);
            // reset last progress
            lastprogress = 0;
            base.OnDoWork(e);
        }
Exemplo n.º 3
0
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }
            PlayBackArgs args     = (PlayBackArgs)e.Argument;
            long         prevtime = 0;

            do
            {
                // if cancel was requested, quit
                if (CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                // play first tick
                long next = h.NextTickTime;
                h.PlayTo(next);
                // adjust delay, based on user's setting of 'speed'
                // as well as daystart (no delay before daystart)
                int delay = next >= args.DayStart ?
                            Util.FTDIFF((int)prevtime, (int)next) * 1000 * args.DELAYSCALE : 0;
                // if not first tick, wait realistic time between ticks
                if (prevtime != 0)
                {
                    System.Threading.Thread.CurrentThread.Join(delay);
                }
                // save time for calculating next day
                prevtime = next;
                // calculate progress
                double progress = 100.0 * (h.TicksProcessed / (double)h.TicksPresent);
                // report progress
                ReportProgress((int)progress);
            }while (h.NextTickTime != HistSim.ENDSIM);
            base.OnDoWork(e);
        }