Changed update function to run asynchronously to avoid blocking GUI updates.
This commit is contained in:
@@ -38,7 +38,7 @@ namespace osrs_toolbox
|
|||||||
{
|
{
|
||||||
DispatcherTimer dt = new DispatcherTimer();
|
DispatcherTimer dt = new DispatcherTimer();
|
||||||
dt.Interval = TimeSpan.FromSeconds(5);
|
dt.Interval = TimeSpan.FromSeconds(5);
|
||||||
dt.Tick += new EventHandler(TimerTick);
|
dt.Tick += new EventHandler(TimerTickAsync);
|
||||||
dt.Start();
|
dt.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +47,11 @@ namespace osrs_toolbox
|
|||||||
DoUpdate(null);
|
DoUpdate(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void TimerTickAsync(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
await DoUpdateAsync(null);
|
||||||
|
}
|
||||||
|
|
||||||
private void DoUpdate(object obj)
|
private void DoUpdate(object obj)
|
||||||
{
|
{
|
||||||
GridOutput = new StackPanel();
|
GridOutput = new StackPanel();
|
||||||
@@ -159,6 +164,118 @@ namespace osrs_toolbox
|
|||||||
OnPropertyChanged(nameof(GridOutput));
|
OnPropertyChanged(nameof(GridOutput));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task DoUpdateAsync(object obj)
|
||||||
|
{
|
||||||
|
GridOutput = new StackPanel();
|
||||||
|
Competition c = new Competition();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
c = await WiseOldMan.GetCompetitionAsync(CompetitionID).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
GridOutput.Children.Add(new OutlinedTextBlock()
|
||||||
|
{
|
||||||
|
Text = "Failed to load competition data",
|
||||||
|
Margin = new Thickness(3),
|
||||||
|
StrokeThickness = 1,
|
||||||
|
Stroke = Brushes.Black,
|
||||||
|
Fill = Brushes.White,
|
||||||
|
FontSize = 20,
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Left,
|
||||||
|
FontWeight = FontWeights.ExtraBold,
|
||||||
|
TextWrapping = TextWrapping.Wrap
|
||||||
|
});
|
||||||
|
OnPropertyChanged(nameof(GridOutput));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int KCSum = 0;
|
||||||
|
string TempOut = c.title;
|
||||||
|
GridOutput.Children.Add(new OutlinedTextBlock()
|
||||||
|
{
|
||||||
|
Text = c.title,
|
||||||
|
Margin = new Thickness(3),
|
||||||
|
StrokeThickness = 1,
|
||||||
|
Stroke = Brushes.Black,
|
||||||
|
Fill = Brushes.White,
|
||||||
|
FontSize = 20,
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Left,
|
||||||
|
FontWeight = FontWeights.ExtraBold,
|
||||||
|
TextWrapping = TextWrapping.Wrap
|
||||||
|
});
|
||||||
|
foreach (CompetitionParticipation cp in c.participations)
|
||||||
|
{
|
||||||
|
StackPanel SubStack = new StackPanel()
|
||||||
|
{
|
||||||
|
Orientation = Orientation.Horizontal
|
||||||
|
};
|
||||||
|
|
||||||
|
Image typeImage = new Image();
|
||||||
|
if (cp.player.type == "ironman")
|
||||||
|
typeImage.Source = ExternalResources.IronImage;
|
||||||
|
else typeImage.Source = ExternalResources.MainImage;
|
||||||
|
typeImage.IsHitTestVisible = false;
|
||||||
|
|
||||||
|
SubStack.Children.Add(typeImage);
|
||||||
|
|
||||||
|
SubStack.Children.Add(new OutlinedTextBlock()
|
||||||
|
{
|
||||||
|
Text = cp.player.displayName,
|
||||||
|
Margin = new Thickness(3),
|
||||||
|
StrokeThickness = 1,
|
||||||
|
Stroke = Brushes.Black,
|
||||||
|
Fill = PlayerName.ToUpper() == cp.player.displayName.ToUpper() ? Brushes.Green : Brushes.White,
|
||||||
|
FontSize = 20,
|
||||||
|
FontWeight = FontWeights.ExtraBold,
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Left,
|
||||||
|
IsHitTestVisible = false
|
||||||
|
});
|
||||||
|
|
||||||
|
SubStack.Children.Add(new OutlinedTextBlock()
|
||||||
|
{
|
||||||
|
Text = string.Format(" - {0} KC", cp.progress.gained.ToString()),
|
||||||
|
Margin = new Thickness(3),
|
||||||
|
StrokeThickness = 1,
|
||||||
|
Stroke = Brushes.Black,
|
||||||
|
Fill = Brushes.White,
|
||||||
|
FontSize = 20,
|
||||||
|
FontWeight = FontWeights.ExtraBold,
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Left,
|
||||||
|
IsHitTestVisible = false
|
||||||
|
});
|
||||||
|
|
||||||
|
KCSum += cp.progress.gained;
|
||||||
|
|
||||||
|
bool AddToDisplay = true;
|
||||||
|
if (HideOtherPlayers && PlayerName.ToUpper() != cp.player.displayName.ToUpper())
|
||||||
|
AddToDisplay = false;
|
||||||
|
else if (HideZeroKC && cp.progress.gained == 0 && PlayerName.ToUpper() != cp.player.displayName.ToUpper())
|
||||||
|
AddToDisplay = false;
|
||||||
|
|
||||||
|
if (AddToDisplay)
|
||||||
|
GridOutput.Children.Add(SubStack);
|
||||||
|
}
|
||||||
|
GridOutput.Children.Add(new OutlinedTextBlock()
|
||||||
|
{
|
||||||
|
Text = string.Format("Total KC: {0}", KCSum),
|
||||||
|
Margin = new Thickness(3),
|
||||||
|
StrokeThickness = 1,
|
||||||
|
Stroke = Brushes.Black,
|
||||||
|
Fill = Brushes.White,
|
||||||
|
FontSize = 20,
|
||||||
|
FontWeight = FontWeights.ExtraBold,
|
||||||
|
VerticalAlignment = VerticalAlignment.Center,
|
||||||
|
HorizontalAlignment = HorizontalAlignment.Left,
|
||||||
|
IsHitTestVisible = false
|
||||||
|
});
|
||||||
|
OnPropertyChanged(nameof(GridOutput));
|
||||||
|
}
|
||||||
|
|
||||||
private void DoCloseApp(object obj)
|
private void DoCloseApp(object obj)
|
||||||
{
|
{
|
||||||
Application.Current.Shutdown();
|
Application.Current.Shutdown();
|
||||||
|
Reference in New Issue
Block a user