I have a code engine that plays long WAV files, playing small pieces in a row using the waveOutOpen and waveOutWrite API methods. To update my user interface when playing a file, from the callback function, when each buffer finishes playing, I call a separate thread (because you want to make as little as possible inside the callback function), which calls the method in my form.
The form contains an EventHandler class level that handles a method in which I update user interface elements with new information. In the form method called from the waveOutWrite callback function, I use the Invoke method as follows:
if (_updatedisplay == null) { // UpdateDisplay contains code to set control properties on the form _updatedisplay = new EventHandler(UpdateDisplay); } Invoke(_updatedisplay);
Everything works, but it seems that from time to time there is a noticeable lag or delay in updating the interface elements. This is easy to see because I use the UpdateDisplay method for animation, so delays appear as βhiccups,β where the sprite freezes for a split second before it moves to its expected position.
Is it possible that sometimes there is a long (maybe 10-15 milliseconds) delay associated with cross-connection? If so, what is the best way to deal with something like this?
Update : by the way, I'm definitely not sure if Invoke here. Another possibility is the lag between when the piece of sound ends and when the callback function is actually called.
Update 2 : for itowlson , I used System.Diagnostics.Stopwatch to compare the lag between Invoke and method invocation. From 1156 measurements, I got 1146 at 0ms, 8 at 1 ms and 2 at 2 ms. I think it's safe to say that Invoke is not my culprit here.
Musigenesis
source share