2

I have login screen in android app which having 45 sec timeout period, it also shows the popup that 'Time out' but after that activity did't close or finish there on click of popup app crash

public HttpClient Client
        {
            get
            {
                if (_client != null) return _client;


                var httpClient = new HttpClient(new NativeMessageHandler {UseCookies = false});
                httpClient.BaseAddress = new Uri(ApplicationSettings.BaseServiceUrl);
                httpClient.Timeout = TimeSpan.FromMilliseconds(45000);
                return _client = httpClient;

            }
        }

        public HttpClient ClientPreAuthenticated
        {
            get
            {
                if (_client != null) return _client;

                var httpClient = new HttpClient(new NativeMessageHandler { UseCookies = false, PreAuthenticate = true });
                httpClient.BaseAddress = new Uri(ApplicationSettings.BaseServiceUrl);
                httpClient.Timeout = TimeSpan.FromMilliseconds(45000);
                return _client = httpClient;
            }
        }

Suggest me any code for this to close this activity

2 Answers2

1

Task.Factory.StartNew(async() => { await Task.Delay(45000); Finish(); });

xleon
  • 6,201
  • 3
  • 36
  • 52
0

In your caller (btnLoginClicked) or whatever, you need to handle Timeout exception or event that has been fired from your httpclient code timing out .. and then simply call Finish() in your catch clause .. if you don't seem to know how to catch a timeout raised from your HttpClient, maybe check this out : How can I tell when HttpClient has timed out?

Community
  • 1
  • 1