I wish I could represent graphically connecting to my remote database, since it is not possible to know the exact connection duration, I thought that an endless progress control should do the job. Currently I am using WaitCursor which doesn't give me satisfaction.
When I use controls such as Progressbar, When I click to begin connection the progress is stopped since it is not used in a separate tread, so I tried to use the backgroundWorker, but have no idea on how to use it to database connection purpose.
My code:
using System;
using System.Linq;
using System.Windows.Forms;
namespace MyNameSpace
{
public partial class Form1 : Form
{
dbDataContext db;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
myProgressBar.Style = ProgressBarStyle.Marquee;
System.Windows.Forms.Application.DoEvents();
db = new dbDataContext();
var Users = from p in db.Users
where p.UserName == TxtUser.Text
select p;
foreach (var record in Users)
{
Global._UserName = record.UserName;
Global._UserID = record.ID;
}
label1.Text = "User ID = " + Global._UserID;
}
}
}