This is my first question here. If I do anything wrong regarding asking or formatting, please tell me!
My program must play something in a Windows Media Player control, wait until it is done playing, then continue with another item.
Below is the entire function:
public void Play(AxWindowsMediaPlayer player, ref bool audioFileFinished)
{
int numberOfIntro = rnd.Next(songIntros.Count); //Randomly select an intro from the list
string introFilePath = songIntros.ElementAt(numberOfIntro).fullPath;
player.URL = introFilePath;
//This task is necessary because the while (!audioFileFinished) will otherwise run in the UI and hang the app.
Task f = Task.Factory.StartNew(() =>
{
while (!audioFileFinished)
{
}
player.URL = fullPath;
});
}
Of course, Visual Studio complains that I may not use a reference variable in the lambda expression. This is logical, as modifying reference variables in asynchronous tasks would be bad, let's keep it at that.
But, I don't have the need to modify it, as it is modified somewhere else in the program. That's why it is a reference variable.
Is there a way to read this variable in a way that Visual Studio accepts? Maybe make it a read only variable? If so, how?
Thanks in advance, Liam