I'm converting the data access layer of an old app from MySql to Salesforce using WinForms, DeveloperForce, Visual Studio 2015, .Net 4.6.1, C#. This is my first real TPL/async/await project.
I'm stuck on how to call ForceClient.UserInfo synchronously.
Anyway, this works:
public ForceClient Connect(){
if (_forceClient == null){
_auth = new AuthenticationClient();
_auth.UsernamePasswordAsync(...).Wait();
_forceClient = new ForceClient(_auth.InstanceUrl, _auth.AccessToken, _auth.ApiVersion);
}
return _forceClient;
}
...
private async Task<int> GetSomeData(){
var response = await Force.Connect().QueryAsync<dynamic>("SELECT...").ConfigureAwait(false);
//load data to local storage
return response.Count
}
So far so good - The connect() blocks the first time until it connects, then I send all my queries at once and load them in pseudo parallel as the results are returned. Yay. Now I want to add a synchronous call to ForceClient.UserInfo() toward the end of the connect method.
This works asyncronously:
userInfo = await _forceClient.UserInfo<UserInfo>(UserInfoEndpointUrl);
But all my attempts to call it synchronously have failed. I've tried .Wait(), .RunSynchronously(), Task.WaitAll, Task.WaitAny, ConfigureAwait(false),... Most things I try end up causing the call to hang indefinitely (thread deadlock)
Help? Thanks!
UserInfoEndpointUrl
being null, empty, or not a well formed Uri? See UserInfo