Wait() private method

private Wait ( ) : bool
return bool
Example #1
0
        protected async override void OnStart()
        {
            try
            {
                await AsyncHelper.Wait();

                PacienteController pacienteController = new PacienteController();

                Usuario usuario = await pacienteController.GetSession();

                if (usuario?.validadeToken > DateTime.MinValue && usuario?.validadeToken > DateTime.UtcNow)
                {
                    MainPage = new NavigationPage(new Views.Home.IndexPage());
                }
                else
                {
                    MainPage = new NavigationPage(new LoginPage());
                }
            }
            catch (Exception ex)
            {
                MainPage = new NavigationPage(new LoginPage());
                Log.Error(ex);
            }
        }
        private async void calendar_OnCalendarTapped(object sender, CalendarTappedEventArgs e)
        {
            viewModel.IsBusy = true;
            await AsyncHelper.Wait(100);

            calendar.SelectedDates = SelectedDates;
            calendar.Refresh();

            await viewModel.Selecionar(e.DateTime.Date);

            await AsyncHelper.Wait(200);

            viewModel.IsBusy = false;
        }
Example #3
0
        public async Task IniciarCadastro()
        {
            if (!IsBusy)
            {
                try
                {
                    IsBusy = true;

                    await AsyncHelper.Wait();

                    await Tela.Navegar(new InicioPage());
                }
                finally
                {
                    IsBusy = false;
                }
            }
        }
Example #4
0
    [PlatformSpecific(TestPlatforms.Windows)] // ThreadPool.UnsafeQueueNativeOverlapped is not supported on Unix
    public static unsafe void PackPosTest1()
    {
        Overlapped           ov       = new Overlapped();
        var                  helper   = new AsyncHelper();
        IOCompletionCallback callback = MyCallback(helper);

        NativeOverlapped *nativeOverlapped = ov.Pack(callback, null);

        try
        {
            Assert.True(nativeOverlapped != null);

            Assert.True(ThreadPool.UnsafeQueueNativeOverlapped(nativeOverlapped));

            Assert.True(helper.Wait());
        }
        finally
        {
            Overlapped.Free(nativeOverlapped);
        }
    }
Example #5
0
    public static unsafe void PackPosTest()
    {
        #pragma warning disable 618
        Overlapped ov = new Overlapped();
        var helper = new AsyncHelper();
        IOCompletionCallback callback = MyCallback(helper);

        NativeOverlapped* nativeOverlapped = ov.Pack(callback);
        try
        {
            Assert.True(nativeOverlapped != null);

            Assert.True(ThreadPool.UnsafeQueueNativeOverlapped(nativeOverlapped));

            Assert.True(helper.Wait());
        }
        finally
        {
            Overlapped.Free(nativeOverlapped);
        }
        #pragma warning restore 618
    }
Example #6
0
    public unsafe static void PackPosTest()
    {
#pragma warning disable 618
        Overlapped           ov       = new Overlapped();
        var                  helper   = new AsyncHelper();
        IOCompletionCallback callback = MyCallback(helper);

        NativeOverlapped *nativeOverlapped = ov.Pack(callback);
        try
        {
            Assert.True(nativeOverlapped != null);

            Assert.True(ThreadPool.UnsafeQueueNativeOverlapped(nativeOverlapped));

            Assert.True(helper.Wait());
        }
        finally
        {
            Overlapped.Free(nativeOverlapped);
        }
#pragma warning restore 618
    }
        public static async Task <bool> IsRemoteReachable(string host, int port = 80, int msTimeout = 2000)
        {
            await AsyncHelper.Wait();

            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException(nameof(host));
            }

            host = host.Replace("http://www.", string.Empty)
                   .Replace("http://", string.Empty)
                   .Replace("https://www.", string.Empty)
                   .Replace("https://", string.Empty)
                   .TrimEnd('/');

            return(await Task.Run(() =>
            {
                try
                {
                    var clientDone = new ManualResetEvent(false);
                    var reachable = false;

                    var hostEntry = new DnsEndPoint(host, port);

                    using (var socket = new Socket(SocketType.Stream, ProtocolType.Tcp))
                    {
                        var socketEventArg = new SocketAsyncEventArgs {
                            RemoteEndPoint = hostEntry
                        };
                        socketEventArg.Completed += (s, e) =>
                        {
                            reachable = e.SocketError == SocketError.Success;

                            clientDone.Set();
                        };

                        clientDone.Reset();
                        bool socketWasAbleToConnect = false;

                        // we need to do this with the timout also here because when you are connected
                        // to a wifi which has no internet connection this line run in a endless timeout
                        Task.Run(() =>
                        {
                            socket.ConnectAsync(socketEventArg);
                            socketWasAbleToConnect = true;
                        }).Wait(msTimeout);

                        if (socketWasAbleToConnect)
                        {
                            clientDone.WaitOne(msTimeout);
                        }

                        return reachable;
                    }
                }
                catch (Exception)
                {
                    return false;
                }
            }));
        }
        public static async Task <bool> HasInternet(string host = "google.com", int msTimeout = 5000)
        {
            await AsyncHelper.Wait();

            return(await IsRemoteReachable(host, 80, msTimeout));
        }