Resolved Play Sound During Task.Delay

in_valparaiso

Member
Joined
Apr 5, 2019
Messages
13
Programming Experience
10+
I am using Task.Delay for a project I am working on, something I have not used before. Code below (thanks to jmcilhinney) looks similar to this:

public static async Task Typing(string text, Label lbl) {
lbl.Visible = true;
await Task.Delay((text.Length / 3) * 1000); // Average person types 3 characters a second. In doing this I can pause the average length of
// time to type the text being shown.
lbl.Visible = false
}

This works perfectly at pausing execution. What the pause does is makes a label visible which says a user is typing. After the delay, the label is hidden and execution proceeds.

Is there way that during the pause I would be able to play a wav file? During the pause I have a wav that sounds like someone is typing.
 
I haven't tested this but I would think that you should be able to create a SoundPlayer object and call Play or PlayLooping before calling Task.Delay. You can call Stop after Task.Delay.
 
Hold off, I'm being seriously stupid. The software requires you be on the domain of the company I work for. Right now I am working from home and am remoted into my computer at work. If the sound is working, I wouldn't hear it at home. Duh!!!
 
Actually, that depends on your remote desktop client and if you checked the option to play sound locally or not. For example, in MSTCS.exe you get these options:
521
 
So confirmed sound is NOT working.

Here is the code I am using:

SoundPlayer snd = new SoundPlayer(Properties.Resources.typing);
lbl.Visible = true;
await Task.Delay((text.Length / 3) * 50);
snd.Stop();
lbl.Visible = false;

Any insight into what I am doing wrong?
 
Have you actually read the documentation for the SoundPlayer class? As far as I can see, you are required to load and play the sound in two separate steps, neither of which you are performing.
 
Back
Top Bottom