misterstick
Programmer
how can i let the parent process of a thead created using a delegate that the thread has finished?
i have a set of web services which, on startup, must be compiled by the server. this takes 20-odd seconds to do, and i'd like this to be done by a splash screen which gives some feedback to the user.
my thought is to have a constructor on the splash screen which takes an array of delegates, each of which is called on a background thread.
when all the background threads have finished, the splash screen should unload itself.
all the above works fine, except that using new Thread(ThreadStart(passedDelegate)) i can't see a way of attaching code to a (currently non-existent) OnEnded() event.
mr s. <
i have a set of web services which, on startup, must be compiled by the server. this takes 20-odd seconds to do, and i'd like this to be done by a splash screen which gives some feedback to the user.
my thought is to have a constructor on the splash screen which takes an array of delegates, each of which is called on a background thread.
when all the background threads have finished, the splash screen should unload itself.
all the above works fine, except that using new Thread(ThreadStart(passedDelegate)) i can't see a way of attaching code to a (currently non-existent) OnEnded() event.
Code:
[COLOR=blue]public delegate void[/color] [COLOR=#2B919F]VoidDelegate[/color]();
[COLOR=green]// test strap form[/color]
[COLOR=blue]public class[/color] [COLOR=#2B919F]Form1[/color] : [COLOR=#2B919F]Form[/color]
{
[COLOR=green]// one for each WebService, currently 11[/color]
[COLOR=blue]private void[/color] Method1()
{
[COLOR=green]// wakes up service for this process,[/color]
[COLOR=green]// takes twenty seconds the first time, [/color]
[COLOR=green]// less than a tenth of a second thereafter[/color]
[COLOR=blue]using[/color] ( [COLOR=#2B919F]WebProxy[/color] proxy = [COLOR=blue]new[/color] [COLOR=#2B919F]WebProxy[/color]() )
{
}
}
[COLOR=blue]private void[/color] button1_Click()
{
[COLOR=#2B919F]VoidDelegate[/color][] delegates = { Method1, ... };
[COLOR=blue]using[/color] ( [COLOR=#2B919F]Form2[/color] form2 = [COLOR=blue]new[/color] [COLOR=#2B919F]Form2[/color](delegates) )
{
form2.ShowDialog(this);
}
}
}
[COLOR=blue]public class[/color] [COLOR=#2B919F]Form2[/color] : [COLOR=#2B919F]Form[/color]
{
[COLOR=blue]public[/color] [COLOR=#2B919F]Form2[/color]() : [COLOR=blue]this[/color]([COLOR=blue]null[/color])
{
}
[COLOR=blue]public[/color] [COLOR=#2B919F]Form2[/color]([COLOR=#2B919F]VoidDelegate[/color][] passedDelegates)
{
[COLOR=blue]if[/color] ( passedDelegates != [COLOR=blue]null[/color] )
{
progressBar1.Maximum = passedDelegates.Length;
[COLOR=blue]foreach[/color] ( [COLOR=#2B919F]VoidDelegate[/color] item [COLOR=blue]in[/color] passedDelegates )
{
[COLOR=blue]new[/color] [COLOR=#2B919F]Thread[/color]([COLOR=blue]new[/color] [COLOR=#2B919F]ThreadStart[/color](item)).Start();
progressBar1.Value++;
}
}
}
[COLOR=green]// i'd like the progress bar to count down again[/color]
[COLOR=green]// as the threads finish, and close the form when[/color]
[COLOR=green]// there's none left... any ideas?[/color]
}
mr s. <