Using Application.Run () for different threads

Please review the following code:

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 );

It seems that everything is working fine: first I see a splash screen, later the mainform starts. But for some reason I get strange errors, for example: graphic elements (infinite ProgressBar) are not displayed correctly.
EDIT : I have two progress panels, one on the splash screen, on the main form. Both of them show the same (wrong) behavior in endless mode: there is no progress, only a clean background. / EDIT
In my opinion, this is due to a call Application.Run()for different threads. These errors can be eliminated by calling any function / mainForm property before running splashscreen - for example,

mainForm.Text = mainForm.Text;

- , - , - ?
splashscreen, , -. . !

+5
4

OMG, :
Application.EnableVisualStyles(); ctor, my mainForm (?). , - . static Main() . (ProgressBarStyle.Marquee) progressbars.
splashscreen , .

+1

, SplashForm, Windows , / . STA. SetApartmentState ,

+4

, Application.Run().

SplashForm splashForm = null;
m_Thread = new Thread(delegate { splashForm = new SplashForm(); System.Windows.Forms.Application.Run(splashForm); });
m_Thread.Start();

, InvokeRequired BeginInvoke. .

+3

, . , , . , kek444 . SplahForm .

So, I assume that this is how you control the Progressbar, or, more generally, how you communicate between two threads.

+1
source

All Articles