Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public partial class SplashScreen : Form { bool DATABASE_CONNECTION; bool RegisteredUser; // if user has been registered string USER_NAME; string PASSWORD; double LIN_x = 0.01; DialogResult result; custom con = new custom(); Timer opac = new Timer(); public SplashScreen() { InitializeComponent(); // initalize splash screen DatabaseStatus(); // set database connection getUserInfo(); // get user information showInfo(); // show app information on splash screen } private void UpdateStatus(string message) { BeginInvoke(new MethodInvoker(() =&gt; richTextBox1.Text += message + Environment.NewLine)); } void checkUser() { UpdateStatus("Loading user settings..."); if (RegisteredUser) { UpdateStatus("User " + USER_NAME + " found." ); if (DATABASE_CONNECTION) { UpdateStatus("Logging on..."); LoginCheck login = new LoginCheck(USER_NAME, PASSWORD); if (login.LOGIN_SUCESS) { UpdateStatus("Success! Loading " + con.AppTitle() + "...please wait"); //UpdateStatus(login.HASH); return hash string from web site fadeSplash(); // begin fade out of form } else { UpdateStatus("There was an error logging in."); } } else { UpdateStatus("No database connection found."); } } else { UpdateStatus("No user found"); Reg(); // Registration form } } private void fadeSplash() { opac.Interval = 12; opac.Tick += new EventHandler(dec); opac.Start(); } private void dec(object sender, EventArgs e) { this.Opacity -= LIN_x; if (this.Opacity &lt; 0.04) { opac.Stop(); this.Hide(); main open = new main(); // start application open.Show(); } } } </code></pre> <p>Here's the code where the fade method doesn't fire during MethodInvoke</p>
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYou still have message boxes and forms being displayed from the non-UI thread. `BackgroundWorker` seems ill-suited for this task, because while you have at least one situation where you need halt execution in the async thread and prompt the user for input, and return that input back to the async thread and continue work. `BackgroundWorker` does not support this; you start work, fire off progress updates, and then an event at the end for when work is completed or cancelled. You need something that is more interactive, which is why I gave you the answer I did.
      singulars
    2. COThat was my bad. The reason it took so long is because I was working on another PC whose windows host did not resolve my private server properly and caused the DATABASE_CONNECTION bool to fail... I had to put a timeout. Anyway, I re-tried your method, with a few minor tweaks, and it worked perfectly fine. My question is though, when should you use Invoke and when should you use a BackgroundWorker? Also, how can I stop the thread? For example, I'd like it to stop if user not found and begin a prompt? Thanks again
      singulars
    3. COI would opt for `BackgroundWorker` if you can, since it's already done for you and easy enough to use. However, `BackgroundWorker` is only going to be useful for you if you only need the following 1. Start work async 2. Fire off progress notifications 3. Signal when work is done. As I stated in my previous comment, your work is more interactive, so `BackgroundWorker` doesn't quite fit the bill (but ALMOST does).
      singulars
 

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