简体   繁体   English

单独屏幕上的启动画面隐藏服务器响应

[英]Splash Screen on separate thread hides server response

I have a C# Windows program that offers a 30-day free trial. 我有一个提供30天免费试用的C#Windows程序。 After that, users must purchase the product or it will lock them out. 之后,用户必须购买产品,否则产品将被锁定。 I made a splash screen to occupy the user while the program queries my web server to see if the user is tampering with data to try to get the program to work without purchasing it. 在程序查询我的Web服务器时,我制作了一个初始屏幕来占据用户的位置,以查看用户是否在篡改数据以尝试使该程序正常运行而无需购买。

On my Windows 8 machine (I'm using .Net Framework 3.5), the splash screen comes up nicely, then the MessageBox comes up (over top of the splash screen) to give them info like "your 30 day free trial has 2 days left". 在我的Windows 8机器上(我使用的是.Net Framework 3.5),启动画面会很好地显示,然后出现MessageBox(位于启动画面上方),以向他们提供信息,例如“您的30天免费试用期为2天剩下”。

However, on my XP machine, the MessageBox is hidden by the splash screen. 但是,在我的XP机器上,启动画面隐藏了MessageBox。 Any ideas on how I can SendToFront() the MessageBox or SendToBack() the splash screen? 关于如何可以将SendBox,SendToFront()或MessageToBack()启动屏幕的任何想法? If I just try to send the form on the splash screen to the back, that's not the same as sending the whole thread to the back. 如果我只是尝试将初始屏幕上的表单发送到背面,则与将整个线程发送到背面不同。

Here's the code to show the splash screen: 这是显示初始屏幕的代码:

static public void ShowSplashScreen() {
    // Make sure it's only launched once.
    if (ms_frmSplash != null)
        return;

    ms_oThread = new Thread(new ThreadStart(SplashScreen.ShowForm));
    ms_oThread.Name = "SplashScreenThread";
    ms_oThread.IsBackground = true;
    ms_oThread.SetApartmentState(ApartmentState.STA);
    ms_oThread.Start();

    while (ms_frmSplash == null || ms_frmSplash.IsHandleCreated == false) {
        System.Threading.Thread.Sleep(TIMER_INTERVAL);
    }
}

Without seeing all of your code, I think what is happening is this: You run your splash screen on a separate thread from your main GUI thread, then launch your message box from the main GUI thread (or yet another thread). 我看不到所有代码,这是怎么回事:您在与主GUI线程不同的线程上运行启动画面,然后从主GUI线程(或另一个线程)启动消息框。 Interfaces on separate threads will act independently (read: erratically) for their Z-order. 单独线程上的接口将按照其Z顺序独立运行(错误阅读)。 Try moving your GUI elements (splash screen and message box) to the main thread. 尝试将GUI元素(启动屏幕和消息框)移至主线程。 Run all long running processes (your server check) on another thread. 在另一个线程上运行所有长时间运行的进程(服务器检查)。

OK, I see what Servy and MikeH are saying, but my concern is that I do a bunch of work and it still doesn't work. 好的,我知道Servy和MikeH在说什么,但我担心的是我做了很多工作,但仍然无法正常工作。 Or, it just isn't predictable from machine to machine. 或者,这只是机器之间无法预测的。 So, the approach I'm going to take is to enhance the splash screen so that it presents the results from the server, rather presenting it in a separate window. 因此,我要采用的方法是增强初始屏幕,以便它显示来自服务器的结果,而不是将其显示在单独的窗口中。 That way, no Z-ordering to worry about at all... 这样,根本就不用担心Z排序...

Thanks for the thoughts, though, I might need them later on! 不过,感谢您的想法,以后我可能会需要它们!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM