new Thread questions

Cdelegate cDelegate = new Cdelegate ( );
ThreadStart trSt = new ThreadStart ( cDelegate.csvTOsql );
Thread trd = new Thread ( trSt, 5000 );
trd.Start ( );

I ran this code and it seems to be working fine, however, two things remain unclear.

(1) Do I have to take any special steps to terminate the thread after work of the delegate is done. If so, how can I do it

(2) I ran it a few times in debug. The delegate csvTOsql transfers some scv files (about 200 of them to SQLEXPRESS server. On the second run and that run only I got a runtime error message that I neglected to copy since I expected it to be repeated. It never came up again but I expect it to show up in the future. I will try to reproduce it from memory:

Thread (perhaps, process ) ID = 58 was locked in competition for resources. Process 58 was chosen as victim.

My question is: shall I increase the buffer size to avoid this to happen or what

Many thanks.

Merry Christmas.




Answer this question

new Thread questions

  • Tuk

    It is documented to throw an exception but doesn't. Experimentally, you get a 256k stack minimum and increments in 64k steps. The error message you got might have something to do with SQL deadlocks.


  • MarijnStevens

    I just noticed another unpleasant thing. After the delegate executes to the end that thread just hangs up and never terminates. There are a couple of statements after the last statement. They remain unexecuted.

    Thanks.



  • Wellnow

    The Thread(ThreadStart, Int32) constructor is actually documented as throwing an ArgumentOutOfRangeException if the thread stack size is less than 131,072 (128k)...

    Try just calling the Thread(ThreadStart) constructor instead (i.e. delete ", 5000" where you create the new thread) and see what happens.

    When the delegate completes the thread terminates...

  • dba123

    Anything less than a page in size for a thread stack should round up to one page (4k on my computer; but it's architecture dependant).

    256k sounds a little strange. Keep in mind that regardless of the stack size you request only a certain amount is commited at the start, as stack usage grows more of the stack is committed a page at a time. The default process thread stack size is 1M. And although all 1M is not commited 1M of viritual memory is now in use.

  • new Thread questions