I have a list of 1 to 4 mediaplayer objects depending on how may are required at the time by the user I need to call the Play method on each 1-4 at the same time.
I don't need them to run at the same time in parallel I just need to call the play method so all in the list start at the same time.
At the moment im doing this
foreach(MyMediaPlayer player in lsPlayers)
{
player.Play();
}
which works ok but I want to know if there is a better way.
I have tried
Parallel.ForEach(ObjectList, (obj) =>
{
// Do parallel work here on each object
});
and Parallel.BeginInvoke
but these all seem to launch in a new thread and that causes an error of trying to access controls on different threads.
I just want to initiate the Play() method at the same time for a possible 1 to 4 media player objects