This project is read-only.
1
Vote

Current thread settings being dropped

description

Tweetinvi.TweetinviConfig.CURRENT_WEB_REQUEST_TIMEOUT = 60000;
Tweetinvi.TweetinviConfig.CURRENT_PROXY_URL = "127.0.0.1....";

var settings = new Tweetinvi.Core.TweetinviSettingsAccessor();
// confirmed is correct settings.CurrentThreadSettings.ProxyURL
This is all set, stepped through, is all working correctly.


Actions are run using:
 TwitterCredentials.ExecuteOperationWithCredentials(cred, () =>
{ 
....
}
yet, when responding to a stream notification, the settings information is dropped!

After making a call to the API

This code runs:
class: HttpClientWebHelper
Method: public HttpResponseMessage GetResponseMessageFromWebRequest(WebRequest webRequest)
  var requestTask = TaskEx.Run(() => GetResponseMessageFromWebRequestAsync(webRequest, _tweetinviSettingsAccessor.WebRequestTimeout));
Just before stepping in, the
tweetinviSettingsAccessor
is correct, my settings are in, but when I step in, the settings are null and are override

after the callback runs, I am back in the code, my current settings are there, then this line runs
 var resultingTask = TaskEx.WhenAny(requestTask, TaskEx.Delay(_tweetinviSettingsAccessor.WebRequestTimeout)).Result;
again, just before, currentthreadsettigns correct, callback executes, settings gone - overidden




So from what I can tell, the async, callback nature of it all, is running things in different "threads" or whatever the terminology and ignoring how other parts of the program function, by having to assign the details to the executing thread, which will detect it later when required and use the parameters.



Any definite ideas on what is going on here? tbh I am a bit lost in it all - and probably is me not understanding things and doing it wrong. The whole paradigm of assigning variables to the executing thread is very different to how I normally do things (assign properties to the object and pass that to execute it), so I am probably trying to do things with the wrong mindset :-s

comments

user_martin wrote Dec 19, 2015 at 4:45 PM

so the actual code that first seems to have lost my threadsettings is the

var requestTask = TaskEx.Run(() => GetResponseMessageFromWebRequestAsync(webRequest, _tweetinviSettingsAccessor.WebRequestTimeout));` more explicity the parameter

this property is
public int WebRequestTimeout
    {
        get { return CurrentThreadSettings.WebRequestTimeout; }
        set { CurrentThreadSettings.WebRequestTimeout = value; }
    }
```` and the property CurrentThreadSettings seems to generate a new instance instead of detecting the existing!

user_martin wrote Dec 19, 2015 at 6:06 PM

urghh seems I got the layout wrong above


so anyway, have hacked a fix in.


The issue is caused by running the method:
 public async Task<HttpResponseMessage> GetResponseMessageFromWebRequestAsync(WebRequest webRequest, int timeout, string sProxy)
from the TaskEx callback action thing. When that function runs, and any functions called from there, there could not access the currenthreadsettings, they didn't exist, so they were overwritten.

The fix was to just make sure that the calling method passes in all currenthreadsettings information that was wanted.

Not very clean / bit hacky, but is working and I can now finish for the day :-)

linvi wrote Dec 20, 2015 at 1:19 AM

Hello there,

I think I would need more of your code to understand whether the issue is with Tweetinvi or if the issue is how you use Tweetinvi.

It would be useful if you could share more. But the way Tweetinvi is supposed to work is that any thread/task in from which you execute an operation will have its own configuration. If you want to use the same one in multiple threads you can simply copy the entire configuration or call an init function that will initialize the Tweetinvi config.

Please send more details regarding this issue.

Cheers,
Linvi

linvi wrote Jan 25, 2016 at 11:35 AM

linvi wrote Jan 30, 2016 at 3:15 AM

Hello there,

Please note that the version you are working with is an old version.
This issue is fixed in the latest version of Tweetinvi so please use this new one!

Regards,
Linvi