I don't see any specific reason for the code posted down below to not
function, but as it isn't a complete example I can not investigate more.
However, the code does have a few problems. It does perform gui operations
from a thread other than the main gui thread. I noticed
ComboBox.SelectedIndex and the MessageBox showing code. I do not believe
either of these calls will trigger a lockup, but there are any number of
other gui operations that will deadlock. V1 of the .NET Compact Framework
only supports gui operations that occur on 1 thread and 1 thread only.
David Wrighton
NET Compact Framework
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "jayderk" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<
[email protected]>
| Subject: Re: .Invoke (delegate)
| Date: Tue, 16 Sep 2003 14:03:34 -0500
| Lines: 249
| Organization: n/a
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: 209.150.197.226
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.compactframework:33506
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| 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);
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
| | > There are no other suggestions. It should work, or the problem is
| elsewhere.
| > Perhaps you want to post few lines of your code
| >
| > | > > I tried this with no success. it still has the same behavior. once
down
| to
| > > this line of code it just stops.
| > >
| > > any other suggestions would be great.
| > > thanks,
| > > Jay
| > >
| > >
| > >
| > > | > > > try replacing
| > > > this.Invoke(new mydelegate(LoadCombo));
| > > > with
| > > > this.Invoke(new EventHandler(LoadCombo));
| > > >
| > > > Also change the LoadCombo definition to be:
| > > >
| > > > void LoadCombo(object sender, EventArgs e)
| > > >
| > > >
| > > > | > > > > Hello all,
| > > > > I have looked at articals such as
| > > > >
| > > >
| > >
| >
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/h
| > > > > tml/BackgroundProcess.asp?frame=true
| > > > >
| > > > > and
| > > > >
| > > > >
| > > >
| > >
| >
|
http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&frame=rig
| > > > > ht&th=dd95b146feb96bd4&seekm=e8YoIORzCHA.2696%40TK2MSFTNGP09#link1
| > > > >
| > > > > to try and find an answer to my problems.
| > > > >
| > > > > I have a control on a form (combo box)
| > > > >
| > > > > I create a polling thread from the form and when a certain event
| > happens
| > > I
| > > > > want to re-populate..
| > > > > I have verified all of the code works accept other then being
called
| > > from
| > > > > the polling thread.
| > > > > I looked in chapter 20 of the core ref. it says to use delegate
with
| > > > invoke
| > > > > but I can not get that to work either..
| > > > >
| > > > >
| > > > > // declared
| > > > > private delegate void mydelegate();
| > > > >
| > > > > //code for the form such as got focus.. yada yada
| > > > >
| > > > >
| > > > > pollingFunction(){
| > > > > blah.. blah..
| > > > > this.Invoke(new mydelegate(LoadCombo));
| > > > > }
| > > > >
| > > > >
| > > > >
| > > > > Please advise.
| > > > >
| > > > > regards,
| > > > > Jay
| > > > >
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|