在我的应用程序项目中,我使用这个来显示我的闪屏图像:
<SplashScreen Include="ImagesSplashScreen.png" />
我也使用一个Mutex
防止应用程序被开了不止一次。但是,即使在App
类构造器中执行Mutex
检查,在执行Mutex
检查之前也会显示启动屏幕。
是否有某种方法可以在闪屏显示之前执行检查,以防止用户在第二次实例中看到它?
您可以以编程方式定义和显示闪屏,这允许您控制它何时显示以及前后发生的事情。添加BuildAction
设置为Resource
的图像。
public partial class App : Application
{
protected override void OnStartup(object sender, StartupEventArgs e)
{
// ...execute pre action here.
SplashScreen splashScreen = new SplashScreen(@"ImagesSplashScreen.png");
splashScreen.Show(true);
base.OnStartup(e);
// ...other code and post action.
}
}
查看SplashScreen
类型了解更多信息,请注意Show
方法有两个重载。该参数决定在加载应用程序后是否自动关闭闪屏。您可以传递false
,并使用Close
方法来确定何时关闭,然后执行您的操作。