G
Guest
Hello all,
I have a problem with SqlDataAdapter.Fill method called from a thread causing an SEHException to be thrown (which originates deep from unmanaged Windows code). Let me show schematic code:
class MyClass
{
Timer timer ;
MyDataSet ds ;
SqlDataAdapter da ;
DataGrid grid ;
public MyClass()
{
//initialize things
grid.DataSource = ds.MyTable ;
}
private void ThreadMethod()
{
//use SqlCommand to do some inserts
ds.MyTable.Clear() ;
da.Fill( ds.MyTable ) ;
}
private void timer_Tick(object sender, System.EventArgs e)
{
Thread t = new Thread( new ThreadStart( this.ThreadMethod ) ) ;
t.Start() ;
}
}
My program imports data from text files, which are generated by another application, into SQL Server database. For that, it uses a timer to periodically check for new files and import their contents into database. I have a DataAdapter and DataSet with a DataGrid bound to it to generate and visualize some statistics on imported data to the user. This DataSet should be refreshed afer every import. The whole read files/insert into database/refresh statistics code is run in thread, so the application doesn't get unresponsive when timer fires. My problem is that soon after the thread exits, I get this exception:
1c260d16()
USER32.DLL!77e12ca8()
USER32.DLL!77e14764()
USER32.DLL!77e15a40()
NTDLL.DLL!77fa15ef()
USER32.DLL!77e134ff()
system.windows.forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(int dwComponentID = 1, int reason = -1, int pvLoopData = 0) + 0x1c0 bytes
system.windows.forms.dll!ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x1f3 bytes
system.windows.forms.dll!ThreadContext.RunMessageLoop(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x50 bytes
system.windows.forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm = {MagazynCelny.MainForm}) + 0x34 bytes
MagazynCelny.exe!MagazynCelny.MainForm.Main() Line 1434 C#
If I comment out the "da.Fill( ds.MyTable)" method call in ThreadMethod, the exception is not thrown. I can't believe it to be a bug in .NET Framework, it would be well documented and fixed by now, what am I doing wrong?
rgds
Alex
I have a problem with SqlDataAdapter.Fill method called from a thread causing an SEHException to be thrown (which originates deep from unmanaged Windows code). Let me show schematic code:
class MyClass
{
Timer timer ;
MyDataSet ds ;
SqlDataAdapter da ;
DataGrid grid ;
public MyClass()
{
//initialize things
grid.DataSource = ds.MyTable ;
}
private void ThreadMethod()
{
//use SqlCommand to do some inserts
ds.MyTable.Clear() ;
da.Fill( ds.MyTable ) ;
}
private void timer_Tick(object sender, System.EventArgs e)
{
Thread t = new Thread( new ThreadStart( this.ThreadMethod ) ) ;
t.Start() ;
}
}
My program imports data from text files, which are generated by another application, into SQL Server database. For that, it uses a timer to periodically check for new files and import their contents into database. I have a DataAdapter and DataSet with a DataGrid bound to it to generate and visualize some statistics on imported data to the user. This DataSet should be refreshed afer every import. The whole read files/insert into database/refresh statistics code is run in thread, so the application doesn't get unresponsive when timer fires. My problem is that soon after the thread exits, I get this exception:
1c260d16()
USER32.DLL!77e12ca8()
USER32.DLL!77e14764()
USER32.DLL!77e15a40()
NTDLL.DLL!77fa15ef()
USER32.DLL!77e134ff()
system.windows.forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(int dwComponentID = 1, int reason = -1, int pvLoopData = 0) + 0x1c0 bytes
system.windows.forms.dll!ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x1f3 bytes
system.windows.forms.dll!ThreadContext.RunMessageLoop(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x50 bytes
system.windows.forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm = {MagazynCelny.MainForm}) + 0x34 bytes
MagazynCelny.exe!MagazynCelny.MainForm.Main() Line 1434 C#
If I comment out the "da.Fill( ds.MyTable)" method call in ThreadMethod, the exception is not thrown. I can't believe it to be a bug in .NET Framework, it would be well documented and fixed by now, what am I doing wrong?
rgds
Alex