55 lines
2.1 KiB
C#
55 lines
2.1 KiB
C#
using System;
|
|||
|
|
using System.Diagnostics;
|
||
|
|
using System.IO;
|
||
|
|
using System.Threading;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using System.Windows;
|
||
|
|
using System.Windows.Markup;
|
||
|
|
using System.Windows.Threading;
|
||
|
|
using SbLauncher;
|
||
|
|
|
||
|
|
public static class UiStress
|
||
|
|
{
|
||
|
|
[STAThread]
|
||
|
|
public static int Main()
|
||
|
|
{
|
||
|
|
var app = new Application();
|
||
|
|
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
||
|
|
var root = AppDomain.CurrentDomain.BaseDirectory;
|
||
|
|
var window = (Window)XamlReader.Parse(File.ReadAllText(Path.Combine(root, "Ui.xaml")));
|
||
|
|
var vm = new MainVm();
|
||
|
|
window.DataContext = vm;
|
||
|
|
vm.ThemeApplier = delegate(string theme) { Theme.Apply(window, theme); };
|
||
|
|
vm.Load(new Paths(root));
|
||
|
|
vm.SetTheme(Theme.Dark);
|
||
|
|
var stopwatch = Stopwatch.StartNew();
|
||
|
|
long previous = 0, longest = 0;
|
||
|
|
int ticks = 0;
|
||
|
|
var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(50) };
|
||
|
|
timer.Tick += delegate
|
||
|
|
{
|
||
|
|
long now = stopwatch.ElapsedMilliseconds;
|
||
|
|
if (previous != 0) longest = Math.Max(longest, now - previous);
|
||
|
|
previous = now;
|
||
|
|
ticks++;
|
||
|
|
vm.ShowSettings = !vm.ShowSettings;
|
||
|
|
vm.SetTheme(ticks % 2 == 0 ? Theme.Dark : Theme.Light);
|
||
|
|
// Оставляем каждую фазу на несколько кадров, чтобы реально
|
||
|
|
// проверить запуск и остановку Storyboard при нагрузке.
|
||
|
|
if (ticks % 10 == 0)
|
||
|
|
vm.ConnectionPhase = new[] { "connecting", "connected", "disconnecting", "idle" }[(ticks / 10) % 4];
|
||
|
|
if (now >= 4000) { timer.Stop(); app.Shutdown(); }
|
||
|
|
};
|
||
|
|
window.Show();
|
||
|
|
timer.Start();
|
||
|
|
Task.Run(delegate
|
||
|
|
{
|
||
|
|
for (int i = 0; i < 20000; i++) vm.AppendLog("stress line " + i);
|
||
|
|
});
|
||
|
|
app.Run();
|
||
|
|
vm.DisposeTimers();
|
||
|
|
Console.WriteLine("UI ticks: " + ticks + ", max interval: " + longest + " ms, log length: " + vm.LogText.Length);
|
||
|
|
return ticks >= 40 && longest < 500 && vm.LogText.Length <= 50000 ? 0 : 1;
|
||
|
|
}
|
||
|
|
}
|