The way I would do it is to cheat, a little.
Create a form with no borders, title bar or anything else, and drop a ProgressBar onto it. Set the ProgressBar.Dock property to Fill. Size the form.
Set ProgressBar.Style to Marquee
Set the Form.StartPosition to CenterParent.
Set the Form.ShowInTaskbar to false.
Add a bool property SuccessfullValidate to the form.
Create a constructor that accepts the value you want to pass to validateuser
Handle the Form.Shown event:
private void frmProgress_Shown(object sender, EventArgs e)
{
BackgroundWorker work = new BackgroundWorker();
work.DoWork += new DoWorkEventHandler(work_DoWork);
work.RunWorkerCompleted += new RunWorkerCompletedEventHandler(work_RunWorkerCompleted);
work.RunWorkerAsync();
}
void work_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Close();
}
void work_DoWork(object sender, DoWorkEventArgs e)
{
try
{
validateuser( Username, s Password, SiteURL, Domain);
SuccessfullValidate = true;
}
catch
{
MessageBox.Show("Error: Unable to connect", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
SuccessfullValidate = false;
}
}
Then all you have to do is create an instance, call ShowDialog and check SuccessfullValidate after it returns.