-2

I need to delay the execution of a method for few seconds using Thread.

But when I use Thread.Sleep(1000); it blocks the UI execution.

Somebody suggest me to use Task.Delay(1000).Wait();. But it doesn't work in the framework 4.0. I can do this using Timer. But I need to achieve this using Thread.

As I was a fresher I can't able to understand the answers provided in the similar questions.

Can any one tell me how to achieve the delayed execution of a method without blocking the UI.

Thanks in advance.

Dennis
  • 37,026
  • 10
  • 82
  • 150

1 Answers1

0

You need to await the task in order to avoid blocking the ui thread.

await Task.Delay(1000)
Abir
  • 31
  • 3
  • check this implementation of Task.Delay in .net 4: http://stackoverflow.com/questions/15341962/how-to-put-a-task-to-sleep-or-delay-in-c-sharp-4-0 – Abir Mar 06 '17 at 08:33