linvi / tweetinvi

Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
MIT License
1.01k stars 219 forks source link

Run methods synchronously like before #1073

Closed cblaze22 closed 4 years ago

cblaze22 commented 4 years ago

What is the best way to run methods .like 4.0.3 Tweetinvi when everything was sync and not async. Having major issues with switching to async and getting deadlocks with a sync application.

linvi commented 4 years ago

I would highly recommend you migrate the code to async nowadays. Though if you do need to have sync code, you can write the following:

// Add a .Result at the end for methods that return a value
var tweet = client.Tweets.PublishTweetAsync("hello").Result;

// Add a .Wait() at the end for methods that only return a Task.
client.Tweets.DestroyRetweetAsync(tweet).Wait();

I hope this helps.