Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Following <A href="http://stackoverflow.com/users/18941/thesoftwarejedi">TheSoftwareJedi's</A> suggestion, I ran some tests, and conclusively proved that it's the use of the PROG_Delegate that causes the exception.</p> <p>If I use MethodInvoker, the code runs without error.</p> <pre><code> private delegate void PROG_Delegate&lt;TGridLine&gt;(DataGridView dgv, IEnumerable&lt;TGridLine&gt; gridLines, string[] columns); public static void PopulateReadOnlyGrid&lt;TGridLine&gt;(DataGridView dgv, IEnumerable&lt;TGridLine&gt; gridLines, string[] columns) { if (dgv.InvokeRequired) { dgv.BeginInvoke(new MethodInvoker(delegate() { PopulateReadOnlyGrid(dgv, gridLines, columns); })); return; } 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; } </code></pre> <p>If I put the PROG_Delegate back in and remove <i>everything else</i> I get the exception back.</p> <pre><code> private delegate void PROG_Delegate&lt;TGridLine&gt;(DataGridView dgv, IEnumerable&lt;TGridLine&gt; gridLines, string[] columns); public static void PopulateReadOnlyGrid&lt;TGridLine&gt;(DataGridView 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 } ); } //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; } </code></pre> <p>So, there's an easy workaround, and the use of the MethodInvoker makes the code more succinct and readable.</p> <p>On a theoretical level, there's still the question as to why it's crashing, given that the PROG_Delegate is legal and it's working for other people. I suspect the best answer we can come to is "some obscure bug", which will remain obscure because coders prefer to use Method Invoker anyway.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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