G
Guest
Hi people,
The code that follows throws an ExecutionEngineException. This was written
in C# (Microsoft Visual C# .NET 69462-335-0000007-18823) using MSDE 7.1
(7.1.3088). The framework is .NET 1.1 (1.1.4322). I tested the program on a
Windows XP Professional/SP1, with a Pentium 4/2.6Ghz processor, with 2Gb RAM.
The code is a single form that when run throws an ExecutionEngineException in
'AddRowsToTable'.
If someone with more knowledge on this matter could help me out, or point it
out to MS.NET developers I'd be grateful. If more information is needed I
will be glad to supply it. Here goes:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Test_EEE_bug
{
public class Form1 : System.Windows.Forms.Form
{
private DataTable dtSource = new DataTable( "Entries" );
private ArrayList logQueue = null;
private System.Timers.Timer logTimer = null;
private readonly object logLock = new object( );
private System.Threading.Thread workerThread = null;
private int counter = 0;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.ComponentModel.Container components = null;
private delegate void SimpleHandler( );
private delegate void AddRowsToTableHandler( DataRow[] drs );
public Form1()
{
InitializeComponent();
DataColumn dtColumn = new DataColumn( "Text", typeof(string) );
dtColumn.ReadOnly = true;
dtSource.Columns.Add( dtColumn );
dataGrid1.SetDataBinding( dtSource, null );
logQueue = new ArrayList( );
logTimer = new System.Timers.Timer( );
logTimer.AutoReset = false;
logTimer.Interval = 250;
logTimer.SynchronizingObject = null;
logTimer.Elapsed += new
System.Timers.ElapsedEventHandler(logTimer_Elapsed);
logTimer.Enabled = true;
}
private void OnLoad(object sender, System.EventArgs e)
{
SpawnThread( );
}
private void SpawnThread()
{
workerThread = new System.Threading.Thread( new
System.Threading.ThreadStart( WorkingThread ) );
workerThread.Start( );
}
private void WorkingThread( )
{
try
{
for( int i = 0; i != 8; ++i )
Write( "Log line " + ++counter );
}
finally
{
this.BeginInvoke( new SimpleHandler( SpawnThread ) );
}
}
public void Write( string text )
{
lock( logLock )
logQueue.Add( text );
}
private void logTimer_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
ArrayList writeOutQueue = null;
lock( logLock )
if( logQueue.Count != 0 )
{
writeOutQueue = logQueue;
logQueue = new ArrayList( );
}
if( writeOutQueue == null )
logTimer.Enabled = true;
else
{
ArrayList dataRows = new ArrayList( );
for( int i = 0; i != writeOutQueue.Count; ++i )
{
DataRow dr1 = dtSource.NewRow( );
dr1[ "Text" ] = writeOutQueue[ i ];
dataRows.Add( dr1 );
}
BeginInvoke( new AddRowsToTableHandler( AddRowsToTable ), new object[]{
(DataRow[]) dataRows.ToArray( typeof(DataRow) ) } );
}
}
private void AddRowsToTable( DataRow[] drs )
{
dataGrid1.SuspendLayout( );
dtSource.BeginLoadData( );
foreach( DataRow dr in drs )
dtSource.Rows.Add( dr );
dtSource.EndLoadData( );
dataGrid1.ResumeLayout( );
logTimer.Enabled = true;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new
System.Windows.Forms.DataGridTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(592, 440);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle1});
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange(new
System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1});
this.dataGridTableStyle1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "";
this.dataGridTableStyle1.ReadOnly = true;
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "Text";
this.dataGridTextBoxColumn1.MappingName = "Text";
this.dataGridTextBoxColumn1.ReadOnly = true;
this.dataGridTextBoxColumn1.Width = 75;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(608, 453);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.OnLoad);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
Kind regards,
The code that follows throws an ExecutionEngineException. This was written
in C# (Microsoft Visual C# .NET 69462-335-0000007-18823) using MSDE 7.1
(7.1.3088). The framework is .NET 1.1 (1.1.4322). I tested the program on a
Windows XP Professional/SP1, with a Pentium 4/2.6Ghz processor, with 2Gb RAM.
The code is a single form that when run throws an ExecutionEngineException in
'AddRowsToTable'.
If someone with more knowledge on this matter could help me out, or point it
out to MS.NET developers I'd be grateful. If more information is needed I
will be glad to supply it. Here goes:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Test_EEE_bug
{
public class Form1 : System.Windows.Forms.Form
{
private DataTable dtSource = new DataTable( "Entries" );
private ArrayList logQueue = null;
private System.Timers.Timer logTimer = null;
private readonly object logLock = new object( );
private System.Threading.Thread workerThread = null;
private int counter = 0;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.DataGridTableStyle dataGridTableStyle1;
private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1;
private System.ComponentModel.Container components = null;
private delegate void SimpleHandler( );
private delegate void AddRowsToTableHandler( DataRow[] drs );
public Form1()
{
InitializeComponent();
DataColumn dtColumn = new DataColumn( "Text", typeof(string) );
dtColumn.ReadOnly = true;
dtSource.Columns.Add( dtColumn );
dataGrid1.SetDataBinding( dtSource, null );
logQueue = new ArrayList( );
logTimer = new System.Timers.Timer( );
logTimer.AutoReset = false;
logTimer.Interval = 250;
logTimer.SynchronizingObject = null;
logTimer.Elapsed += new
System.Timers.ElapsedEventHandler(logTimer_Elapsed);
logTimer.Enabled = true;
}
private void OnLoad(object sender, System.EventArgs e)
{
SpawnThread( );
}
private void SpawnThread()
{
workerThread = new System.Threading.Thread( new
System.Threading.ThreadStart( WorkingThread ) );
workerThread.Start( );
}
private void WorkingThread( )
{
try
{
for( int i = 0; i != 8; ++i )
Write( "Log line " + ++counter );
}
finally
{
this.BeginInvoke( new SimpleHandler( SpawnThread ) );
}
}
public void Write( string text )
{
lock( logLock )
logQueue.Add( text );
}
private void logTimer_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
ArrayList writeOutQueue = null;
lock( logLock )
if( logQueue.Count != 0 )
{
writeOutQueue = logQueue;
logQueue = new ArrayList( );
}
if( writeOutQueue == null )
logTimer.Enabled = true;
else
{
ArrayList dataRows = new ArrayList( );
for( int i = 0; i != writeOutQueue.Count; ++i )
{
DataRow dr1 = dtSource.NewRow( );
dr1[ "Text" ] = writeOutQueue[ i ];
dataRows.Add( dr1 );
}
BeginInvoke( new AddRowsToTableHandler( AddRowsToTable ), new object[]{
(DataRow[]) dataRows.ToArray( typeof(DataRow) ) } );
}
}
private void AddRowsToTable( DataRow[] drs )
{
dataGrid1.SuspendLayout( );
dtSource.BeginLoadData( );
foreach( DataRow dr in drs )
dtSource.Rows.Add( dr );
dtSource.EndLoadData( );
dataGrid1.ResumeLayout( );
logTimer.Enabled = true;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGridTableStyle1 = new System.Windows.Forms.DataGridTableStyle();
this.dataGridTextBoxColumn1 = new
System.Windows.Forms.DataGridTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(592, 440);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.TableStyles.AddRange(new
System.Windows.Forms.DataGridTableStyle[] {
this.dataGridTableStyle1});
//
// dataGridTableStyle1
//
this.dataGridTableStyle1.DataGrid = this.dataGrid1;
this.dataGridTableStyle1.GridColumnStyles.AddRange(new
System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn1});
this.dataGridTableStyle1.HeaderForeColor =
System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle1.MappingName = "";
this.dataGridTableStyle1.ReadOnly = true;
//
// dataGridTextBoxColumn1
//
this.dataGridTextBoxColumn1.Format = "";
this.dataGridTextBoxColumn1.FormatInfo = null;
this.dataGridTextBoxColumn1.HeaderText = "Text";
this.dataGridTextBoxColumn1.MappingName = "Text";
this.dataGridTextBoxColumn1.ReadOnly = true;
this.dataGridTextBoxColumn1.Width = 75;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(608, 453);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.OnLoad);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
Kind regards,