Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
AnswerDOUBLE POST Pin
dan!sh 3-Feb-10 3:00
professional dan!sh 3-Feb-10 3:00 
AnswerRe: write information in control via non UI class Pin
aurelcly3-Feb-10 3:05
aurelcly3-Feb-10 3:05 
AnswerREPOST Pin
Luc Pattyn3-Feb-10 3:14
sitebuilderLuc Pattyn3-Feb-10 3:14 
Questionwinform Pin
aurelcly3-Feb-10 2:55
aurelcly3-Feb-10 2:55 
AnswerRe: winform Pin
Luc Pattyn3-Feb-10 2:57
sitebuilderLuc Pattyn3-Feb-10 2:57 
AnswerRe: winform Pin
Not Active3-Feb-10 2:59
mentorNot Active3-Feb-10 2:59 
AnswerDon't repost Pin
Not Active3-Feb-10 3:01
mentorNot Active3-Feb-10 3:01 
QuestionWinforms and SQL Threading Problem [modified] Pin
Uray Frank3-Feb-10 1:32
Uray Frank3-Feb-10 1:32 
Hi all

I have a big issue with threading in Windows Forms.

For example:
I have a .NET 2.0 (VS 2008) Windows Forms Solution
with one form in it (as default Form1).
I make this Form1 as MdiContainer.
In the Load Event I create a new thread and after this I
load a new Windows Form as Mdi Child.
In the thread I just read about 1mio rows in a DataTable
using standard DataReader.

Now because I have created a new thread, I would expect
the load time of this large amount of data would not affect
the loaded form, but it does ...
After starting the application, I grab the child form and I
just move it arround the Container form and it allways
hangs for some time ...

When I reduce the amount of data to just some rows,
the form feels free.

Here I send you my code and I would be very very happy
for a solution of this problem !

Thanks and best regards
Frank Uray

private static bool StopThread = false;

private void Form1_Load(object sender, EventArgs e)
{

   System.Threading.Thread local_Thread = new System.Threading.Thread(RunThread);
   local_Thread.Start();

   System.Windows.Forms.Form local_Form = new System.Windows.Forms.Form();
   local_Form.MdiParent = this;
   local_Form.Show();

}

private void RunThread()
{

   System.Data.SqlClient.SqlConnection local_SqlConnection = new System.Data.SqlClient.SqlConnection();
   System.Data.SqlClient.SqlCommand local_SqlCommand = new System.Data.SqlClient.SqlCommand();
   System.Data.SqlClient.SqlDataReader local_SqlDataReader;
   local_SqlConnection.ConnectionString = @"Data Source=MyServer\MyInstance;Initial    Catalog=master;Integrated Security=true;";
   local_SqlConnection.Open();

   while (!StopThread)
   {

      // Command Object setzen
      local_SqlCommand.CommandText = "SELECT * FROM SomeTable";
      local_SqlCommand.CommandTimeout = 0;
      local_SqlCommand.Connection = local_SqlConnection;

      // DataReader
      local_SqlDataReader = local_SqlCommand.ExecuteReader();

      // DataTable füllen
      System.Data.DataTable local_DataTable = new System.Data.DataTable();
      local_DataTable.BeginLoadData();
      local_DataTable.Load(local_SqlDataReader);
      local_DataTable.EndLoadData();

      System.Threading.Thread.Sleep(2000);
   }

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{ StopThread = true; }


modified on Wednesday, February 3, 2010 9:14 AM

AnswerRe: Winforms and SQL Threading Problem Pin
Luc Pattyn3-Feb-10 1:51
sitebuilderLuc Pattyn3-Feb-10 1:51 
GeneralRe: Winforms and SQL Threading Problem Pin
Uray Frank3-Feb-10 2:45
Uray Frank3-Feb-10 2:45 
GeneralRe: Winforms and SQL Threading Problem Pin
Luc Pattyn3-Feb-10 2:53
sitebuilderLuc Pattyn3-Feb-10 2:53 
GeneralRe: Winforms and SQL Threading Problem Pin
Uray Frank3-Feb-10 3:20
Uray Frank3-Feb-10 3:20 
AnswerRe: Winforms and SQL Threading Problem Pin
Luc Pattyn3-Feb-10 3:49
sitebuilderLuc Pattyn3-Feb-10 3:49 
GeneralRe: Winforms and SQL Threading Problem Pin
Uray Frank3-Feb-10 4:07
Uray Frank3-Feb-10 4:07 
GeneralRe: Winforms and SQL Threading Problem Pin
Luc Pattyn3-Feb-10 4:12
sitebuilderLuc Pattyn3-Feb-10 4:12 
GeneralRe: Winforms and SQL Threading Problem Pin
Uray Frank3-Feb-10 4:18
Uray Frank3-Feb-10 4:18 
GeneralRe: Winforms and SQL Threading Problem Pin
Luc Pattyn3-Feb-10 4:29
sitebuilderLuc Pattyn3-Feb-10 4:29 
GeneralRe: Winforms and SQL Threading Problem Pin
Uray Frank3-Feb-10 4:30
Uray Frank3-Feb-10 4:30 
GeneralRe: Winforms and SQL Threading Problem Pin
Luc Pattyn3-Feb-10 4:36
sitebuilderLuc Pattyn3-Feb-10 4:36 
GeneralRe: Winforms and SQL Threading Problem Pin
Uray Frank3-Feb-10 4:45
Uray Frank3-Feb-10 4:45 
GeneralRe: Winforms and SQL Threading Problem Pin
Luc Pattyn3-Feb-10 5:12
sitebuilderLuc Pattyn3-Feb-10 5:12 
QuestionLINQ to parse EventLog Query [modified] Pin
Sunil G3-Feb-10 1:11
Sunil G3-Feb-10 1:11 
AnswerRe: LINQ to parse EventLog Query Pin
Ravi Bhavnani3-Feb-10 2:01
professionalRavi Bhavnani3-Feb-10 2:01 
AnswerRe: LINQ to parse EventLog Query Pin
Pete O'Hanlon3-Feb-10 2:14
mvePete O'Hanlon3-Feb-10 2:14 
AnswerRe: LINQ to parse EventLog Query Pin
Palash Biswas3-Feb-10 3:17
Palash Biswas3-Feb-10 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.