I have a form that takes a few seconds to load. So I want to show a small form with the text "Download, please wait." When the form is completed, the boot form should be closed.
So, I made a simple class that shows the boot form in the stream:
public class ShowLoadingForm
{
Thread _thread;
public void Show()
{
try
{
_thread = new Thread(new ThreadStart(ShowForm));
_thread.SetApartmentState(ApartmentState.STA);
_thread.IsBackground = true;
_thread.Start();
}
catch (Exception ex)
{
ErrorMessages.UnknownError(true, ex);
}
}
private void ShowForm()
{
LoadingForm f = new LoadingForm();
f.TopMost = true;
f.ShowInTaskbar = true;
f.SetText(" Loading... ");
f.Show();
}
public void Close()
{
_thread.Abort();
}
}
In the main form, I have:
_loadingForm = new ShowLoadingForm();
_loadingForm.Show();
BUT. After this piece of code, I do something in the main form: this.Opacity = 0 ;. At this point, I see in the debugger that the thread is stopped and ThreadStateExceptionthrown, and the download form disappears.
Why is this?
source
share