Fixed PageDialoge Threads

This commit is contained in:
TheJoKlLa 2022-05-31 12:35:15 +02:00
parent aa29d7d733
commit f6105f10ac
4 changed files with 74 additions and 20 deletions

View File

@ -32,10 +32,28 @@ namespace Borepin.Base
{ {
case ConnectionStatusChange.Connected: case ConnectionStatusChange.Connected:
IsConnected = true; IsConnected = true;
await LoadAPIData().ConfigureAwait(false); try
{
await LoadAPIData().ConfigureAwait(false);
}
catch
{
IsConnected = false;
await _API.Disconnect().ConfigureAwait(false);
_API.UnbindAllEvents();
}
break; break;
case ConnectionStatusChange.Reconnected: case ConnectionStatusChange.Reconnected:
await ReloadAPIData().ConfigureAwait(false); try
{
await ReloadAPIData().ConfigureAwait(false);
}
catch
{
IsConnected = false;
await _API.Disconnect().ConfigureAwait(false);
_API.UnbindAllEvents();
}
break; break;
case ConnectionStatusChange.ConnectionLoss: case ConnectionStatusChange.ConnectionLoss:
try try
@ -84,7 +102,16 @@ namespace Borepin.Base
if(_API.IsConnected) if(_API.IsConnected)
{ {
await LoadAPIData().ConfigureAwait(false); try
{
await LoadAPIData().ConfigureAwait(false);
}
catch
{
IsConnected = false;
await _API.Disconnect().ConfigureAwait(false);
_API.UnbindAllEvents();
}
} }
} }
#endregion #endregion

View File

@ -89,7 +89,11 @@ namespace Borepin.PageModel.AddServerProcess
if (_API.IsConnected) if (_API.IsConnected)
{ {
await _API.Disconnect().ConfigureAwait(false); if (_API.IsConnected)
{
await _API.Disconnect().ConfigureAwait(true);
_API.UnbindAllEvents();
}
} }
try try
@ -98,23 +102,32 @@ namespace Borepin.PageModel.AddServerProcess
} }
catch (ConnectingFailedException) catch (ConnectingFailedException)
{ {
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok").ConfigureAwait(false); Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok").ConfigureAwait(false);
IsBusy = false; IsBusy = false;
});
return; return;
} }
catch (AuthenticationFailedException) catch (AuthenticationFailedException)
{ {
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to authenticate to server.", "Ok").ConfigureAwait(false); Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to authenticate to server.", "Ok").ConfigureAwait(false);
IsBusy = false; IsBusy = false;
});
return; return;
} }
catch(Exception) catch(Exception)
{ {
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unexpected Error.", "Ok").ConfigureAwait(false); Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unexpected Error.", "Ok").ConfigureAwait(false);
IsBusy = false; IsBusy = false;
});
return; return;
} }

View File

@ -90,9 +90,13 @@ namespace Borepin.PageModel.AddServerProcess
} }
catch (UriFormatException) catch (UriFormatException)
{ {
await _PageDialogService.DisplayAlertAsync("Connection failed", "Server address is invaild.", "Ok").ConfigureAwait(false); Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync("Connection failed", "Server address is invaild.", "Ok").ConfigureAwait(false);
IsBusy = false;
});
IsBusy = false;
return; return;
} }
@ -103,9 +107,13 @@ namespace Borepin.PageModel.AddServerProcess
} }
catch(ConnectingFailedException) catch(ConnectingFailedException)
{ {
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok").ConfigureAwait(false); Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok").ConfigureAwait(false);
IsBusy = false;
});
IsBusy = false;
return; return;
} }

View File

@ -128,20 +128,26 @@ namespace Borepin.PageModel
try try
{ {
await _API.Connect(Connection_Item).ConfigureAwait(true); await _API.Connect(Connection_Item).ConfigureAwait(false);
} }
catch(ConnectingFailedException) catch(ConnectingFailedException)
{ {
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok").ConfigureAwait(false); Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to connect to server.", "Ok").ConfigureAwait(false);
IsBusy = false; IsBusy = false;
});
return; return;
} }
catch(AuthenticationFailedException) catch(AuthenticationFailedException)
{ {
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to authenticate to server.", "Ok").ConfigureAwait(false); Device.BeginInvokeOnMainThread(async () =>
{
await _PageDialogService.DisplayAlertAsync("Connection failed", "Unable to authenticate to server.", "Ok").ConfigureAwait(false);
IsBusy = false; IsBusy = false;
});
return; return;
} }