Inheritance: IDisposable
Ejemplo n.º 1
0
 public DelayedCall(DelayedCall<object>.Callback cb, object data)
     : this()
 {
     PrepareDCObject(this, 0, false);
     oldCallback = cb;
     oldData = data;
 }
Ejemplo n.º 2
0
 public DelayedCall(DelayedCall<object>.Callback cb, int milliseconds, object data)
     : this()
 {
     PrepareDCObject(this, milliseconds, false);
     oldCallback = cb;
     oldData = data;
     if (milliseconds > 0) Start();
 }
Ejemplo n.º 3
0
        public MetroTaskWindow(int duration, Control userControl)
            : this()
        {
            controlContainer.Controls.Add(userControl);
            userControl.Dock = DockStyle.Fill;
            closeTime = duration * 500;

            if (closeTime > 0)
                timer = DelayedCall.Start(UpdateProgress, 5);
        }
Ejemplo n.º 4
0
        public static DelayedCall StartAsync(Callback cb, int milliseconds)
        {
            DelayedCall dc = CreateAsync(cb, milliseconds);

            if (milliseconds > 0)
            {
                dc.Start();
            }
            else if (milliseconds == 0)
            {
                dc.FireNow();
            }
            return(dc);
        }
Ejemplo n.º 5
0
        public MetroTaskWindow(int duration, Control userControl, Point location)
            : this()
        {
            controlContainer.Controls.Add(userControl);
            userControl.Dock = DockStyle.Fill;
            closeTime = duration * 500;

            if (location == Point.Empty)
            {
                enableTaskBar = true;
            }
            else
            {
                Location = location;
            }

            if (closeTime > 0)
                timer = DelayedCall.Start(UpdateProgress, 5);
        }
Ejemplo n.º 6
0
		protected static void PrepareDCObject(DelayedCall dc, int milliseconds, bool async)
		{
			if (milliseconds < 0)
			{
				throw new ArgumentOutOfRangeException("milliseconds", "The new timeout must be 0 or greater.");
			}
			
			// Get the current synchronization context if required, with dummy fallback
			dc.context = null;
			if (!async)
			{
				dc.context = SynchronizationContext.Current;
				if (dc.context == null)
					throw new InvalidOperationException("Cannot delay calls synchronously on a non-UI thread. Use the *Async methods instead.");
			}
			if (dc.context == null) dc.context = new SynchronizationContext();   // Run asynchronously silently
			
			dc.timer = new System.Timers.Timer();
			if (milliseconds > 0) dc.timer.Interval = milliseconds;
			dc.timer.AutoReset = false;
			dc.timer.Elapsed += dc.Timer_Elapsed;
			
			Register(dc);
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Creates a new asynchronous <c>DelayedCall</c> instance. The callback function will be invoked on a <c>ThreadPool</c> thread.
		/// </summary>
		/// <param name="cb">Callback function</param>
		/// <param name="milliseconds">Time to callback invocation</param>
		/// <returns>Newly created <c>DelayedCall</c> instance that can be used for later controlling of the invocation process</returns>
		public static DelayedCall CreateAsync(Callback cb, int milliseconds)
		{
			DelayedCall dc = new DelayedCall();
			PrepareDCObject(dc, milliseconds, true);
			dc.callback = cb;
			return dc;
		}
Ejemplo n.º 8
0
        protected void Start(Control control, TransitionType transitionType, int duration, AnimationAction actionHandler, AnimationFinishedEvaluator evaluatorHandler)
        {
            this.targetControl = control;
            this.transitionType = transitionType;
            this.actionHandler = actionHandler;
            this.evaluatorHandler = evaluatorHandler;

            this.counter = 0;
            this.startTime = 0;
            this.targetTime = duration;

            timer = DelayedCall.Start(DoAnimation, duration);
        }
Ejemplo n.º 9
0
 protected static void Unregister(DelayedCall dc)
 {
     lock (dcList)
     {
         dcList.Remove(dc);
     }
 }
Ejemplo n.º 10
0
 public DelayedCall(DelayedCall.Callback cb) : this()
 {
     DelayedCall.PrepareDCObject(this, 0, false);
     this.callback = cb;
 }
        private void UpdateProgress()
        {
            if (elapsedTime == closeTime)
            {
                timer.Dispose();
                timer = null;
                Close();
                return;
            }

            elapsedTime += 5;

            if (cancelTimer)
                elapsedTime = 0;

            double perc = (double)elapsedTime / ((double)closeTime / 100);
            progressWidth = (int)((double)Width * (perc / 100));
            Invalidate(new Rectangle(0,0,Width,5));

            if (!cancelTimer)
                timer.Reset();
        }
Ejemplo n.º 12
0
 protected virtual void Timer_Elapsed(object o, ElapsedEventArgs e)
 {
     this.FireNow();
     DelayedCall.Unregister(this);
 }
Ejemplo n.º 13
0
 public void FireNow()
 {
     this.OnFire();
     DelayedCall.Unregister(this);
 }
Ejemplo n.º 14
0
 public void Dispose()
 {
     DelayedCall.Unregister(this);
     this.timer.Dispose();
 }
Ejemplo n.º 15
0
 public DelayedCall(DelayedCall <object> .Callback cb, object data) : this()
 {
     DelayedCall.PrepareDCObject(this, 0, false);
     this.oldCallback = cb;
     this.oldData     = data;
 }
Ejemplo n.º 16
0
		protected static void Register(DelayedCall dc)
		{
			lock (dcList)
			{
				// Keep a reference on this object to prevent it from being caught by the Garbage Collector
				if (!dcList.Contains(dc))
					dcList.Add(dc);
			}
		}
Ejemplo n.º 17
0
		protected static void Unregister(DelayedCall dc)
		{
			lock (dcList)
			{
				// Free a reference on this object to allow the Garbage Collector to dispose it
				// if no other reference is kept to it
				dcList.Remove(dc);
			}
		}
Ejemplo n.º 18
0
 protected static void Register(DelayedCall dc)
 {
     lock (dcList)
     {
         if (!dcList.Contains(dc))
             dcList.Add(dc);
     }
 }