Esempio n. 1
2
 public override void AddTimeout(Timeout timeout)
 {
     new Timer((a) =>
     {
         BlockInvoke(delegate()
         {
             timeout.Run(null);
             if (!timeout.ShouldContinueToRepeat())
                 ((Timer)a).Dispose();
         });
     }, null, timeout.begin, timeout.span);
 }
Esempio n. 2
0
 public void AddTimeout(Timeout timeout)
 {
     TimerWatcher t = new TimerWatcher (timeout.begin, timeout.span, evloop, HandleTimeout);
     t.UserData = timeout;
     t.Start ();
 }
Esempio n. 3
0
 public abstract void AddTimeout(Timeout timeout);
		/// <summary>
		/// Establishes an async timeout for the interval.
		/// </summary>
		/// <param name="interval">The timeout interval without units.</param>
		/// <returns>The timeout specification.</returns>
		public Timeout TimeoutAfter(int interval)
		{
			lock (this)
			{
				if (timeout != null)
				{
					throw new InvalidOperationException(
						"A timeout has already been established");
				}
				timeout = new Timeout(this, interval);
			}
			return timeout;
		}
		public Task<Position> GetPositionAsync (int timeout, bool includeHeading)
		{
			if (timeout < 0)
				throw new ArgumentOutOfRangeException ("timeout");

			// The built in timeout does not cancel, it throws an exception, so we'll setup our own.
			IAsyncOperation<Geoposition> pos = GetGeolocator().GetGeopositionAsync (TimeSpan.Zero, TimeSpan.FromDays (365));
			Timeout timer = new Timeout (timeout, pos.Cancel);

			var tcs = new TaskCompletionSource<Position>();

			pos.Completed = (op, s) =>
			{
				timer.Cancel();

				switch (s)
				{
					case AsyncStatus.Canceled:
						tcs.SetCanceled();
						break;
					case AsyncStatus.Completed:
						tcs.SetResult (GetPosition (op.GetResults()));
						break;
					case AsyncStatus.Error:
						Exception ex = op.ErrorCode;
						if (ex is UnauthorizedAccessException)
							ex = new GeolocationException (GeolocationError.Unauthorized, ex);
							
						tcs.SetException (ex);
						break;
				}
			};

			return tcs.Task;
		}
		public Task<Position> GetPositionAsync (int timeout, CancellationToken token, bool includeHeading)
		{
			if (timeout < 0)
				throw new ArgumentOutOfRangeException ("timeout");

			IAsyncOperation<Geoposition> pos = GetGeolocator().GetGeopositionAsync (TimeSpan.FromTicks (0), TimeSpan.FromDays (365));
			token.Register (o => ((IAsyncOperation<Geoposition>)o).Cancel(), pos);

			Timeout timer = new Timeout (timeout, pos.Cancel);

			var tcs = new TaskCompletionSource<Position>();

			pos.Completed = (op, s) =>
			{
				timer.Cancel();

				switch (s)
				{
					case AsyncStatus.Canceled:
						tcs.SetCanceled();
						break;
					case AsyncStatus.Completed:
						tcs.SetResult (GetPosition (op.GetResults()));
						break;
					case AsyncStatus.Error:
						Exception ex = op.ErrorCode;
						if (ex is UnauthorizedAccessException)
							ex = new GeolocationException (GeolocationError.Unauthorized, ex);
							
						tcs.SetException (ex);
						break;
				}
			};

			return tcs.Task;
		}