Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Async causing deadlock

$
0
0

I am running into a problem with using async. I get a deadlock every few days and I have a feeling it has to do with something in the below code chunk. Does the code look like async best practice or does something stand out that would cause a deadlock?

        public async void Speak()
        {
            this.timer1.Stop();

            if (listBox2.SelectedIndex > -1)
            {
                string Name = (string)this.listBox2.SelectedItem;
                selectedVoice = Name;

            }

            await  Task.Run (() => { Work( selectedVoice); });

            if(Started)
            {
              TotalTime = pElapsedTime;
              TimeLeft = pElapsedTime;
              this.label3.Text = TotalTime.ToString() + " Seconds";
              this.timer1.Start();
            }
       }


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>