Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

New Post: multi thread behavior

$
0
0
Hi,

I am not sure what is your problem here. Tweetinvi provides 2 set of methods, async and synchronous.
Now I have to admit that some of the methods does not have their async equivalent.

But if you need an operation to be run another why don't you just simply do so?
Task.Factory.StartNew(() =>
{
    var user = User.GetLoggedUser();
    Console.WriteLine(user);
});
Now you need to understand the credentials system between threads.
As you are probably aware each thread uses a distinct Credentials object.

It means that invoking TwitterCredentials.SetCredentials in one thread will not affect the other threads.
Though when a thread is created, Tweetinvi will initialize the ThreadCredentials to the value stored in TwitterCredentials.ApplicationCredentials.

Tweetinvi async methods are ThreadSafe. Now if you want to execute your code and ensure that your credentials are ThreadSafe it is a good idea to set the credentials at each start of a new Thread.
Task.Factory.StartNew(() =>
{
    // Ensuring the credentials information of the Thread
    TwitterCredentials.SetCredentials("", "", "", "");
    var user = User.GetLoggedUser();
    Console.WriteLine(user);
});
If you need more help concerning Multi-Threading I will need some piece of code.
Cheers,
Linvi

Viewing all articles
Browse latest Browse all 4126

Trending Articles



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