gpt4 book ai didi

c# - SplashScreen.Close(Timespan.FromMilliseconds(int)) : Is there an Event dispatched at Timespan Complete?

转载 作者:太空狗 更新时间:2023-10-29 17:56:26 31 4
gpt4 key购买 nike

C# WPF 应用程序

我有一个 SplashScreen通过使用在启动时显示最短时间

Thread.Sleep(int); //int = milliseconds to display splash screen

当达到该休眠时间时,代码恢复并且 SplashScreen 淡出以通过使用关闭

SplashScreen.Close(Timespan.FromMilliseconds(int)); //int = milliseconds fade-out

此时我想暂停一下,等待 SplashScreen 变为 100% 透明并完全关闭,然后继续其他任务,I.E.写入控制台或显示主窗口。

当 (TimeSpan.FromMilliseconds(int)) 完成时是否会触发事件?还有其他建议吗?

namespace StartupSplash
{
public class SplashScreenStartup
{
//IMPORTANT:set image property to Resource and NOT Splash Screen
private SplashScreen Splash = new SplashScreen("Resources/SplashScreen.png");

public void SplashScreenStartUp()
{
Splash.Show(false, true);
Thread.Sleep(3000); // Pause code, display splash screen 3 seconds
Splash.Close(TimeSpan.FromMilliseconds(3000)); // 3 second splash fade-out
// I want to wait until splash screen fadeOut has completed before
// this next console output is performed.
Console.WriteLine("Executes before Splash fadeOut completes.");
}

}

最佳答案

也许这段代码可以帮到你。使用后台 worker 类:

BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (o, ea) =>
{
// Dispatcher.Invoke commands the dispatcher to do something
Dispatcher.Invoke((Action)(() => Splash.Close(TimeSpan.FromMilliseconds(3000)));
// Sleeps this worker but NOT the UI
Thread.Sleep(3000);
};
worker.RunWorkerCompleted += (o, ea) =>
{
// Open your mainwindow sample
MainWindow w = new MainWindow();
w.Show();
};

//Runs the worker on its own thread
worker.RunWorkerAsync();

这应该开始关闭启动画面,然后休眠,完成后将打开主窗口。实际上,我使用与此非常相似的东西来为我的 WPF 应用程序实现登录和获取信息,同时显示进度条并将其中的文本更新为诸如“连接到服务器”、“登录”和“获取数据”之类的内容。

关于c# - SplashScreen.Close(Timespan.FromMilliseconds(int)) : Is there an Event dispatched at Timespan Complete?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13213625/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com