views:

282

answers:

1

I'm calling and getting results back from an async web service call that provides an array of objects to display in a grid on a hand-held windows mobile.

At one point I had the UI updating properly using InvokedRequired and Invoke. Now the first time I run the emulator and Visual Studio 2008 it will work but subsequent calls seem to hang on the Invoke method call with no other breakpoints being hit in the code.

This app is using the .Net CF 2.0 SP1 and is targeting a WinMo 6.1 device. I recently switched from a virtual dev environment running XP to the host laptop which runs Vista.

private delegate void UpdateGrid(WebServiceItems[] items);

private void DoGridUpdate(WebServiceItems[] items)
    {
        // Choose the correct grid based on the tab index
        DataGrid grid;
        if (tabSelectedIndex == 0)
            grid = gridA;
        else
            grid = gridB;

        if (grid.InvokeRequired)
        {
            grid.Invoke(new UpdateGrid(DoGridUpdate), new object[] { items });

            return;
        }

        Cursor.Current = Cursors.Default;
        grid.DataSource = items;
        if (items.Length > 0)
        {
            DataGridTableStyle tableStyle = new DataGridTableStyle();
            tableStyle.MappingName = items.GetType().Name;

            DataGridTextBoxColumn column = new DataGridTextBoxColumn();
            column.Width = 230;
            column.MappingName = "Column1";
            column.HeaderText = "Column1";
            tableStyle.GridColumnStyles.Add(column);

            column = new DataGridTextBoxColumn();
            column.Width = 70;
            column.MappingName = "Column2";
            column.HeaderText = "Column2";
            tableStyle.GridColumnStyles.Add(column);

            grid.TableStyles.Clear();
            grid.TableStyles.Add(tableStyle);
        }
    }
A: 

I forgot about this question but found a resolution. I had come from an ASP.NET background and at the time did not realize about keeping the service in scope, I'm surprised it worked at all.

The declaration for the service was in the button onclick event so I moved it to the form constructor and made the service global for the form so all methods had access to it and everything now works as intended.

Brian