0

I have need to make a splash screen with a progress bar. My problem is that I cannot link the main form with the splash screen:

public LogIn_Form() {
    Thread t = new Thread(new ThreadStart(SplashStart));
    t.Start();
    Thread.Sleep(5000);
    InitializeComponent();
    t.Abort();
}

public void SplashStart() {
    Application.Run(new Form1());
}

Where I have "Application.Run(new Form1());" it gives me an error under Form1.

This is the splash screen form:

public SplashScreen_Form() {
    InitializeComponent();
    timer.Start();
}

private void timer_Tick(object sender, EventArgs e) {
    this.Opacity += 0.07;

    pbrLoad.Increment(1);
    if (pbrLoad.Value == 100) 
        timer.Stop();
}

private void SplashScreen_Form_Load(object sender, EventArgs e) {
    this.Opacity = 0;
    timer.Enabled = true;
}

Now I need to keep it like that but with no errors.

Stachu
  • 5,677
  • 3
  • 30
  • 34
GameOver
  • 97
  • 1
  • 2
  • 7
  • What error are you getting? – Ming Slogar Jan 20 '14 at 19:26
  • 2
    Using `Thread.Abort()` is a very bad thing to do. The entire thing is very oddly designed, I recommend using a custom [`ApplicationContext`](http://msdn.microsoft.com/en-us/library/ms157901%28v=vs.110%29.aspx) that starts your splash screen and your main form instead of starting each one separately and not create any extra threads at all. – Scott Chamberlain Jan 20 '14 at 19:27
  • 1
    The UI exists in one thread you should not attempt to interact with it from another. You also shouldn't be using `Thread.Abort()`. – Lloyd Jan 20 '14 at 19:28
  • Can you post a code sample for me? – GameOver Jan 20 '14 at 19:38

0 Answers0