Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just FYI, not sure if it'll fix anything, but your Invoke method can be simplified. This also removes the need for that delegate (possibly leading to a fix?):</p> <pre><code>dgv.BeginInvoke(new MethodInvoker(delegate() { PopulateReadOnlyGrid(dgv, gridLines, columns); })); </code></pre> <p>Your code runs fine for me when I paste it in a form (after commenting out your GridUtils stuff). I even call the method both from the gui thread and the non-gui thread. I tried it in 3.5 and 2.0. Works fine.... (!?)</p> <p>Try this code:</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Threading; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private delegate void PROG_Delegate&lt;TGridLine&gt;(Control dgv, IEnumerable&lt;TGridLine&gt; gridLines, string[] columns); public static void PopulateReadOnlyGrid&lt;TGridLine&gt;(Control dgv, IEnumerable&lt;TGridLine&gt; gridLines, string[] columns) { if (dgv.InvokeRequired) { dgv.BeginInvoke ( new PROG_Delegate&lt;TGridLine&gt;(PopulateReadOnlyGrid&lt;TGridLine&gt;), new object[] { dgv, gridLines, columns } ); return; } MessageBox.Show("hi"); //GridUtils.StatePreserver statePreserver = new GridUtils.StatePreserver(dgv); //System.Data.DataTable dt = CollectionHelper.ConvertToDataTable&lt;TGridLine&gt;((gridLines)); //dgv.DataSource = dt; //dgv.DataMember = ""; //dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; //GridUtils.OrderColumns&lt;TGridLine&gt;(dgv, columns); //statePreserver.RestoreState(); //dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; } private void button1_Click(object sender, EventArgs e) { PopulateReadOnlyGrid(this, new int[] { 1, 2, 3 }, new string[] { "a" }); ThreadPool.QueueUserWorkItem(new WaitCallback((a) =&gt; { PopulateReadOnlyGrid(this, new int[] { 1, 2, 3 }, new string[] { "a" }); })); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload