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

New Post: Suggestions on Async Operation where each Operation Could Have Different Credentials

$
0
0
Code like the following.. where there are many async methods queued up.... end up with the global static application context... because the context gets rolled back in the method below...


TwitterCredentials.ExecuteOperationWithCredentials(credentials, () =>
                {
                        var tweet = TweetAsync.PublishTweet(message);
                        if (tweet == null)
                        {
                            logger.Error(string.Format("Twitter tweet of message for user id {0} failed, exception description: {1}, status code: {2}, details: {3}.", 
                                accessToken, ExceptionHandler.GetLastException().TwitterDescription,
                                ExceptionHandler.GetLastException().StatusCode, 
                                ExceptionHandler.GetLastException().TwitterExceptionInfos.First().Message ));
                            // just continue with notification processing and log errors about Twitter
                        }
                });

    public void ExecuteOperationWithCredentials(IOAuthCredentials credentials, Action operation)
    {
        var initialCredentials = CurrentThreadCredentials;
        CurrentThreadCredentials = credentials;
        operation();
        __CurrentThreadCredentials = initialCredentials;__
    }

Viewing all articles
Browse latest Browse all 4126

Trending Articles