1

I'm looking for a best way to deal with text that moves from right to left.

So, I have this working code:

// write text for simulation view
File.WriteAllText("text1.txt", textBox1.Text, Encoding.UTF8);   
// delete temporary processed video with overlayed text
ProcessFileOperations.deleteFile("text1.avi");

ProcessFileOperations.overlayText(text1ColorButton.BackColor.Name, filePath, 0);
mediaPlayer.URL = "text1.avi";
mediaPlayer.Ctlcontrols.play();

This creates a video with overlayed scrolling text and instantly plays it as simulation. The problem arrives when I write text it fast windowmediaplayer is "going down" for a while - black image. How can let to user to put text and update media files with some delay or pause NOT to "freeze" main thread?

Elmatsidis Paul
  • 385
  • 1
  • 7
  • 19

1 Answers1

1

this makes the changes run another thread and once completed media player runs with new file

await Task.Run(()=>{
  // write text for simulation view
    File.WriteAllText("text1.txt", textBox1.Text, Encoding.UTF8);   
    // delete temporary processed video with overlayed text
    ProcessFileOperations.deleteFile("text1.avi");


ProcessFileOperations.overlayText(text1ColorButton.BackColor.Name, filePath, 0);
});

mediaPlayer.URL = "text1.avi";
mediaPlayer.Ctlcontrols.play();
Krishna
  • 1,945
  • 1
  • 13
  • 24
  • I use .NET 4. I got the error: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. Galaxy G2D C:\Users\Power User\Desktop\290317-chroma-work\C_Sharp_Demo\Form1.cs – Elmatsidis Paul Mar 29 '17 at 12:37
  • @PaulElmatsidis check this http://stackoverflow.com/questions/9110472/using-async-await-on-net-4 – Krishna Mar 29 '17 at 12:49
  • @PaulElmatsidis or you can use normal threading to run that process asynchronously – Krishna Mar 29 '17 at 12:50