I am using the following code, what I need to know is, what do I do if I
want to pass parameters to DoSomeWork? I don't understand how the
callback variable is passed to DoSomeWork.
private void SpawnSomeWork()
{
IProgressCallback callback; // = ???
System.Threading.ThreadPool.QueueUserWorkItem(
new System.Threading.WaitCallback(
DoSomeWork ),
callback );
}
private void DoSomeWork( object status )
{
IProgressCallback callback = status as IProgressCallback;
try
{
callback.Begin( 0, 100 );
for( int i = 0 ; i < 100 ; ++i )
{
callback.SetText( String.Format( "Performing op: {0}", i )
);
callback.StepTo( i );
if( callback.IsAborting )
{
return;
}
// Do a block of work
if( callback.IsAborting )
{
return;
}
}
}
catch( System.Threading.ThreadAbortException )
{
// We want to exit gracefully here (if we're lucky)
}
catch( System.Threading.ThreadInterruptedException )
{
// And here, if we can
}
finally
{
if( callback != null )
{
callback.End();
}
}
}
*** Sent via Developersdex http://www.developersdex.com ***