J
jayderk
I am trying to get a datagrid on a form to repopulate when a certain event
occurs on a polling thread for a comm unit.
I have verified the code... and it all works accept for repopulating the
datagrid.
here is the other functions and declares
public class frmOrders: Yada Yada
{
private EventHandler myDelegate; // predefined delegate
public frmOrders(){
//
// Required for Windows Form Designer support
//
InitializeComponent();
// delegate instance to invoke
myDelegate = new EventHandler(LoadGrid);
..
..
..
private void LoadGrid(object sender,EventArgs e)
{
DataRow newRow;
myDataTable.Clear();
if(!grid_needs_to_be_loaded ||
valid_orders == null || valid_orders.Count <= 0)
return;
grid_needs_to_be_loaded = false;
foreach(ClipOrderObj order in valid_orders)
{
newRow = myDataTable.NewRow();
newRow["Description"] = order.Order_Desc.ToString();
newRow["Quantity"] = order.Order_Quantity;
myDataTable.Rows.Add(newRow);
}
}
this code works perfect. it does this.invoke(myDelegate).. goes to the
function, updates, and returns .. like it should
private void poll_function()
{
this.Invoke(myDelegate);
return;
}
this code does NOT work.. it gets down to this.Invoke(myDelegate) and locks
up.
Any suggestions would be great.
private void poll_function()
{
string COM_PORT = "COM8:\0";
string twoAsbyte = Convert.ToString((char)0x02);
bool comm_port_return = false;
// try
// {
// comm_port_return = Bluetooth.OpenCommPort(COM_PORT);
// }
// catch(Exception e)
// {
// MessageBox.Show("Could not open comm port\nMessage:" +
e.Message.ToString() );
// }
while(!terminate && !comm_port_return){
byte[] thebuff = new byte[100];
// try{thebuff = Bluetooth.ReadPortWord();}
// catch(Exception commex)
// {
// bool open_comm_try = Bluetooth.OpenCommPort(COM_PORT);
// continue;
// }
if(cboCustomer.SelectedIndex < 0)
{
Thread.Sleep(4000);
continue;
}
// if (thebuff[4] == 0)
// continue;
// string bufferData = Bluetooth.convertDllData(thebuff);
// string cleanBuffer = bufferData.Replace("\r\n"," ");
// string stringToSplit = cleanBuffer.Replace(twoAsbyte,"");
string[] goodData = new string[50];
goodData[0] = "11326812";
goodData[1] = "11326773";
goodData[2] = "11326804";
goodData[3] = "11326819";
// goodData = stringToSplit.Split(' ');
for(int i=0; i < goodData.Length-1; i++)
{
string mydata =
goodData.ToString().Trim().Substring(0,goodData.Length - 4);
if( mydata .Length <= 0)
continue;
int index = IsInCurrentOrder(mydata );
if( index >= 0 )
{// it is in the valid_list
last_row_hit = index;
}
else if( index == -1)
{// it is new
ClipOrderObj orderRec = new ClipOrderObj();
orderRec.Code = mydata;
cm.GetProductInformation(orderRec);
if(orderRec.Order_Desc.Length <= 0)
{
MessageBox.Show(barcode + " is not in current database","Item
Not found",
MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
continue;
}
orderRec.Customer_Id =
((CustomerInfo)customer_list[cboCustomer.SelectedIndex]).Customer_Id.ToStrin
g();
orderRec.Order_Quantity = 1;
orderRec.Order_Status = "N";
valid_orders.Add(orderRec);
}
}
grid_needs_to_be_loaded = true;
this.Invoke(myDelegate);
}
occurs on a polling thread for a comm unit.
I have verified the code... and it all works accept for repopulating the
datagrid.
here is the other functions and declares
public class frmOrders: Yada Yada
{
private EventHandler myDelegate; // predefined delegate
public frmOrders(){
//
// Required for Windows Form Designer support
//
InitializeComponent();
// delegate instance to invoke
myDelegate = new EventHandler(LoadGrid);
..
..
..
private void LoadGrid(object sender,EventArgs e)
{
DataRow newRow;
myDataTable.Clear();
if(!grid_needs_to_be_loaded ||
valid_orders == null || valid_orders.Count <= 0)
return;
grid_needs_to_be_loaded = false;
foreach(ClipOrderObj order in valid_orders)
{
newRow = myDataTable.NewRow();
newRow["Description"] = order.Order_Desc.ToString();
newRow["Quantity"] = order.Order_Quantity;
myDataTable.Rows.Add(newRow);
}
}
this code works perfect. it does this.invoke(myDelegate).. goes to the
function, updates, and returns .. like it should
private void poll_function()
{
this.Invoke(myDelegate);
return;
}
this code does NOT work.. it gets down to this.Invoke(myDelegate) and locks
up.
Any suggestions would be great.
private void poll_function()
{
string COM_PORT = "COM8:\0";
string twoAsbyte = Convert.ToString((char)0x02);
bool comm_port_return = false;
// try
// {
// comm_port_return = Bluetooth.OpenCommPort(COM_PORT);
// }
// catch(Exception e)
// {
// MessageBox.Show("Could not open comm port\nMessage:" +
e.Message.ToString() );
// }
while(!terminate && !comm_port_return){
byte[] thebuff = new byte[100];
// try{thebuff = Bluetooth.ReadPortWord();}
// catch(Exception commex)
// {
// bool open_comm_try = Bluetooth.OpenCommPort(COM_PORT);
// continue;
// }
if(cboCustomer.SelectedIndex < 0)
{
Thread.Sleep(4000);
continue;
}
// if (thebuff[4] == 0)
// continue;
// string bufferData = Bluetooth.convertDllData(thebuff);
// string cleanBuffer = bufferData.Replace("\r\n"," ");
// string stringToSplit = cleanBuffer.Replace(twoAsbyte,"");
string[] goodData = new string[50];
goodData[0] = "11326812";
goodData[1] = "11326773";
goodData[2] = "11326804";
goodData[3] = "11326819";
// goodData = stringToSplit.Split(' ');
for(int i=0; i < goodData.Length-1; i++)
{
string mydata =
goodData.ToString().Trim().Substring(0,goodData.Length - 4);
if( mydata .Length <= 0)
continue;
int index = IsInCurrentOrder(mydata );
if( index >= 0 )
{// it is in the valid_list
last_row_hit = index;
}
else if( index == -1)
{// it is new
ClipOrderObj orderRec = new ClipOrderObj();
orderRec.Code = mydata;
cm.GetProductInformation(orderRec);
if(orderRec.Order_Desc.Length <= 0)
{
MessageBox.Show(barcode + " is not in current database","Item
Not found",
MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
continue;
}
orderRec.Customer_Id =
((CustomerInfo)customer_list[cboCustomer.SelectedIndex]).Customer_Id.ToStrin
g();
orderRec.Order_Quantity = 1;
orderRec.Order_Status = "N";
valid_orders.Add(orderRec);
}
}
grid_needs_to_be_loaded = true;
this.Invoke(myDelegate);
}