L
Lee Alexander
I wrote some code in a method called in a separate thread via the ThreadPool
where I expected my code in a Finally section to be called but it never did.
I'd be interested to know why this is the case? Here's some code to repro
the behaviour:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
static void DoSomething( object state )
{
try
{
int count = 0;
while( true )
{
Console.WriteLine( count++ );
System.Threading.Thread.Sleep( 500 );
}
}
finally
{
Console.WriteLine( "Thread Finished" );
}
}
static void Main( string[] args )
{
System.Threading.ThreadPool.QueueUserWorkItem( new
System.Threading.WaitCallback( DoSomething ) );
System.Threading.Thread.Sleep( 5000 );
System.Console.WriteLine( "Process Done" );
}
}
}
Regards
Lee Alexander
www.feedghost.com
An RSS Reader for Vista & XP
Synchronize, search, tag and share.
where I expected my code in a Finally section to be called but it never did.
I'd be interested to know why this is the case? Here's some code to repro
the behaviour:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
static void DoSomething( object state )
{
try
{
int count = 0;
while( true )
{
Console.WriteLine( count++ );
System.Threading.Thread.Sleep( 500 );
}
}
finally
{
Console.WriteLine( "Thread Finished" );
}
}
static void Main( string[] args )
{
System.Threading.ThreadPool.QueueUserWorkItem( new
System.Threading.WaitCallback( DoSomething ) );
System.Threading.Thread.Sleep( 5000 );
System.Console.WriteLine( "Process Done" );
}
}
}
Regards
Lee Alexander
www.feedghost.com
An RSS Reader for Vista & XP
Synchronize, search, tag and share.