Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>MSDN says concerning thread.Abort, "Calling this method usually terminates the thread." </p> <p>There is a countless number of ways you can close out your Splash Screen without using thread.Abort. </p> <p>Here is one such way to accomplish what it appears you are trying to do.</p> <p>SplashScreen.cs </p> <pre><code> namespace ICAMReports { public partial class SplashScreen : Form { ManualResetEventSlim splashDone; public SplashScreen(ManualResetEventSlim SplashDone) { splashDone=SplashDone; InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { progressBar1.Increment(1); if (progressBar1.Value == 100) { splashDone.Set(); this.Close(); } } } } </code></pre> <p>Form1.CS</p> <pre><code> namespace ICAMReports { public partial class Form1 : Form { ManualResetEventSlim splashDone = new ManualResetEventSlim(false); public Form1() { InitializeComponent(); Thread th = new Thread(new ThreadStart(splashScreen)); th.Start(); splashDone.Wait(); } public void splashScreen() { Application.Run(new SplashScreen(splashDone)); } //this where the rest of code is placed.... } } </code></pre> <p>splashDone.Wait() will accomplish the same thing you were trying to do with the Sleep() but instead you should use your loading Bar in your Splash Screen to tell you when to end the thread. Actually in this scenario it really doesn't make any sense to have the splash Screen on a separate thread because the sleep/wait will pause the main form from loading anything until the Splash Screen is finished. Suppose you had resource intensive things in your Form1 that you wanted to load while the Splash Screen is distracting the user. You would do something like this instead of just pausing the Form1 entirely(since the entire point of using a separate thread is that they both run simultaneously.</p> <p>SplashScreen.cs </p> <pre><code> namespace ICAMReports { public partial class SplashScreen : Form { Form parent; delegate void show(); public SplashScreen(Form Parent) { parent=Parent; InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { progressBar1.Increment(1); if (progressBar1.Value == 100) { parent.Invoke(new show(()=&gt;{parent.Opacity=100;})); this.Close(); } } } } </code></pre> <p>Form1.CS</p> <pre><code> namespace ICAMReports { public partial class Form1 : Form { public Form1() { InitializeComponent(); Thread th = new Thread(new ThreadStart(splashScreen)); th.Start(); this.Opacity=0; } public void splashScreen() { Application.Run(new SplashScreen(this)); } //this where the rest of code is placed.... } } </code></pre> <p>edit: Responding to loading bar animation</p> <p>The loading bar will move and look different depending on the version and settings of Windows you are using. You can't use a Thread.Sleep to let the loading bar catch up because it pauses the loadingBar1 animation. You need to give your loading bar about ~10% to catch up(adjust it as needed) this should fix your problem of the loading bar animation.</p> <pre><code> int i = 0; private void timer1_Tick(object sender, EventArgs e) { if(i++&lt;100)progressBar1.Value++; if (i == 110) { splashDone.Set(); this.Close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload