0

I have a big winform application that takes long time to load so I wrote a splash screen for it.

The problem is that when I show the splash form from a new thread, the progress bar will freeze 2 or 3 times while loading. But when I do it using a separated process I haven't any problem and it has a smooth motion.

I want to know that what's the difference between a new thread and a separated process in such a situation.

Thanks

oMatrix
  • 352
  • 1
  • 4
  • 10
  • 1
    Post the relevant code please – nmat May 28 '13 at 13:18
  • How do you associate the progress bar's progress with application for load? Meaning on what event does the progress bar shows progress? – YK1 May 28 '13 at 15:59
  • I show the splash dialog before application.Run(new MainForm()). The Progress bar animation uses a Timer for it's movement. – oMatrix May 29 '13 at 04:38
  • Take a look at [Windows Forms Splash Screen](https://stackoverflow.com/a/32421479/3110834). – Reza Aghaei Dec 02 '19 at 05:44

3 Answers3

0

Simply think of it as the Main form has it's own thread. When you are doing something on that thread that is task intensive, it doesn't get a chance to update the UI. However, when you create a new thread, you are in effect creating a new worker that can update the splash screen UI, while the Main form's thread is performing its workload.

David C
  • 3,610
  • 3
  • 21
  • 23
0

A process is an executing instance of an application. For example, when you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of that process.

Another difference between a thread and a process is that threads within the same process share the same address space, whereas different processes do not.

Shafqat Masood
  • 2,532
  • 1
  • 17
  • 23
0

It could be because the UI for the splash screen needs to be in a completely separate thread from the main window with a totally separate Windows message queue.

To run some UI in a different thread from the main thread you will need to start a new message pump for it, because message queues cannot be shared between threads.

To start a new message pump, call Application.Run(yourSplashScreen); from the separate thread. Create your splash screen form from the separate thread too.

Note that you cannot directly manipulate controls in one form from code executing in a different form that you started in a separate thread. You would have to use Control.Invoke() to do so, just like you normally do with multiple threads.

Anyway, if you use a separate message queue like this it could help to prevent the stalling that you're seeing.

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
  • I did a test like this: static void Main() { Thread t = new Thread(new ThreadStart(splash)); t.start(); Application.Run(new MainForm()); } void splash() { Application.Run(new SplashForm()); } But it still has the same problem. – oMatrix May 28 '13 at 13:56
  • @oMatrix Ah that's a shame. There must be some other problem then. But using a separate message queue for a splash screen is certainly something to know about. – Matthew Watson May 28 '13 at 14:17