HarjeetSingh
asked on
Cross-thread Problem
Hi
My Requirement is something like timeControl. What I want my application constantly look at server (at certain interval) and as soon as new record is inserted in Database it Show back in DataGridView. Pl help me
static string conn = "Data Source=192.168.0.18;Initia l Catalog=hotel;User ID=sa";
SqlConnection cn = new SqlConnection(conn);
SqlDataAdapter ad;
SqlCommand cmd;
DataSet ds;
Thread th;
public frmDownload()
{
InitializeComponent();
//Control.CheckForIllegalC rossThread Calls = false;
}
private void frmDownload_Load(object sender, EventArgs e)
{
cn.Open();
try
{
th = new Thread(new ThreadStart(GetRemoteData1 ));
th.Priority = ThreadPriority.Highest;
th.Start();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message , "Unable to Connect Remote Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void GetRemoteData1()
{
cmd = new SqlCommand("SpBookingGuest Detail", cn);
ad = new SqlDataAdapter(cmd);
ds = new DataSet();
ad.Fill(ds);
DataGridRemote.DataSource = ds.Tables[0];
//////There Error Raises ---- Cross-thread Windows Form Control
Thread.Sleep(1000);
}
}
Pl Help
My Requirement is something like timeControl. What I want my application constantly look at server (at certain interval) and as soon as new record is inserted in Database it Show back in DataGridView. Pl help me
static string conn = "Data Source=192.168.0.18;Initia
SqlConnection cn = new SqlConnection(conn);
SqlDataAdapter ad;
SqlCommand cmd;
DataSet ds;
Thread th;
public frmDownload()
{
InitializeComponent();
//Control.CheckForIllegalC
}
private void frmDownload_Load(object sender, EventArgs e)
{
cn.Open();
try
{
th = new Thread(new ThreadStart(GetRemoteData1
th.Priority = ThreadPriority.Highest;
th.Start();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message
}
}
void GetRemoteData1()
{
cmd = new SqlCommand("SpBookingGuest
ad = new SqlDataAdapter(cmd);
ds = new DataSet();
ad.Fill(ds);
DataGridRemote.DataSource = ds.Tables[0];
//////There Error Raises ---- Cross-thread Windows Form Control
Thread.Sleep(1000);
}
}
Pl Help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.