在不同的线程使用Application.Run()

编程入门 行业动态 更新时间:2024-10-27 16:39:44
本文介绍了在不同的线程使用Application.Run()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请看看下面的代码:

var splashForm = new SplashForm(); m_Thread = new Thread( () => System.Windows.Forms.Application.Run( splashForm ) ) m_Thread.Start(); // Do some initialization // ... // the following method just invokes `Close()` on the right thread splashForm.Shutdown(); // Loop until the thread is no longer alive // ... System.Windows.Forms.Application.Run( mainForm );

看起来好像一切工作正常:首先我看到启动画面,后来被MainForm的开始。但不知何故,我得到奇怪的错误,如:图形元素(一个无尽的进度)都显示不正确 修改:我有两个progressbars,一个在启动画面上在MainForm的。他们都表现出endlessmode相同的(错误)的行为:没有进步,只是单纯的背景 /修改 在我看来,这是由于 Application.Run()在不同的线程。像,例如

It looks as if all works fine: first I see the splashscreen, later the mainform gets started. But somehow I get strange errors, like: graphical elements (a endless ProgressBar) are not showing up correctly. EDIT: I have two progressbars, one on the splashscreen, on on the mainform. They both show the same (wrong) behaviour in endlessmode: no progress, just the pure background./EDIT In my opinion this is due to the call of Application.Run() on different threads. This errors can be eliminated by calling any function/property of the mainForm before starting the splashscreen - like, for instance

mainForm.Text = mainForm.Text;

任何人都可以请确认该代码会引起问题 - 或者说,它应该表现得好吧,我不得不查找错误别的地方? 我已经找了启动画面的实现,我知道它可以做不同。但我有兴趣了解这个执行和可能出现的问题。 !谢谢

Can anyone please confirm that this code can cause problems - or that it should behave alright and I have to look for the error somewhere else? I already looked for splashscreen implementations and I know that it can be done differently. But I am interested in understanding this implementation and its possible problems. Thanks!

推荐答案

03,我找到了答案: 应用程序。 EnableVisualStyles(); 被称为在构造函数,如果我的MainForm(为什么?)。它在创建任何控件之前被调用。它移动到静态Main()的伎俩。视觉样式都需要无尽的(ProgressBarStyle.Marquee)progressbars。 现在这个闪屏解决方案的作品,因为它应该。

OMG, I found the answer: Application.EnableVisualStyles(); was called in the ctor if my mainForm (WHY?). It has to be called before any controls are created. Moving it to the static Main() did the trick. The visual styles are required for endless (ProgressBarStyle.Marquee) progressbars. Now this splashscreen solution works as it should.

更多推荐

在不同的线程使用Application.Run()

本文发布于:2023-06-04 21:18:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/505238.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   Application   Run

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!