Exemple #1
0
        async Task ConnectDiscoveredSpheroAsync(TimeSpan timeout)
        {
            TaskCompletionSource <bool> completionSource =
                new TaskCompletionSource <bool>();

            if (this.HasProvider && this.HasSphero &&
                !this.HasConnectedSphero)
            {
                EventHandler <Robot> robotsHandler = null;

                robotsHandler = (s, robot) =>
                {
                    completionSource.SetResult(true);
                };
                this.Provider.ConnectedRobotEvent += robotsHandler;

                AsyncExceptionSwallowingContext ctx = new AsyncExceptionSwallowingContext();

                ctx.Replace();
                this.Provider.ConnectRobot(this.sphero);
                ctx.Replace();

                await Task.WhenAny(completionSource.Task, Task.Delay(timeout));

                this.Provider.ConnectedRobotEvent -= robotsHandler;
            }
        }
Exemple #2
0
    async Task ConnectDiscoveredSpheroAsync(TimeSpan timeout)
    {
      TaskCompletionSource<bool> completionSource =
        new TaskCompletionSource<bool>();

      if (this.HasProvider && this.HasSphero &&
        !this.HasConnectedSphero)
      {
        EventHandler<Robot> robotsHandler = null;

        robotsHandler = (s, robot) =>
        {
          completionSource.SetResult(true);
        };
        this.Provider.ConnectedRobotEvent += robotsHandler;

        AsyncExceptionSwallowingContext ctx = new AsyncExceptionSwallowingContext();

        ctx.Replace();
        this.Provider.ConnectRobot(this.sphero);
        ctx.Replace();

        await Task.WhenAny(completionSource.Task, Task.Delay(timeout));
        this.Provider.ConnectedRobotEvent -= robotsHandler;
      }
    }