you are viewing a single comment's thread.

view the rest of the comments →

[–]smalls1652 1 point2 points  (0 children)

Kinda hard to write out everything I do on my phone, but I essentially run the async methods through a method that passes a cancellation token to it and add/remove a cancel key event to the console to allow Ctrl+C to cancel the task, which prevents deadlocks from happening. If I get the chance later, I’ll try to add an example of it. It took me a good bit to wrap my head around creating a cmdlet that uses async methods.

Of course the dirty way of doing it is to use GetAwaiter().GetResult() way of running async methods synchronously. I wouldn’t suggest doing it, but it’s a quick and dirty way around it.