Last post Aug 22, 2016 03:04 AM by Yohann Lu
Aug 20, 2016 10:13 AM|BlackRiver19877|LINK
I have a strange problem that I cannot resolve, so I was hoping someone could perhaps point me in the right direction.
I have a function that I use to GET some data from a WEB API endpoint.
This is the function:
public async Task<SDI.IShared.CommunicationService.WebServices.Responses.RONNA.AppStageClass> SetAppStage(int AppStageCode)
SDI.CRONDesktopClient.Classes.StaticMembers.StaticValues.AppStages = IShared.Enumerators.RONNA.APIOrSignalR.API;
SDI.IShared.CommunicationService.WebServices.Responses.RONNA.AppStageClass lassie = null;
using (var client = new HttpClient())
SDI.CRONDesktopClient.Classes.StaticMembers.StaticObjects.ErrorHandler.InsertMessages("-", "Unutar SetAppStage", "SetAppStage", true);
client.BaseAddress = new Uri(ApiAddress);
SDI.CRONDesktopClient.Classes.StaticMembers.StaticObjects.ErrorHandler.InsertMessages("-", "Šaljem GETASYNC", "SetAppStage", true);
HttpResponseMessage response = await client.GetAsync("api/v1/MainMenu/AppStage?_SID=" + SDI.CRONDesktopClient.Classes.StaticMembers.StaticObjects.LoginResponseObject.SessionID + "&_AppStageCode=" + AppStageCode);
SDI.CRONDesktopClient.Classes.StaticMembers.StaticObjects.ErrorHandler.InsertMessages("-", "Response SUCCESS", "SetAppStage", true);
lassie = await response.Content.ReadAsAsync<SDI.IShared.CommunicationService.WebServices.Responses.RONNA.AppStageClass>();
SDI.CRONDesktopClient.Classes.StaticMembers.StaticObjects.ErrorHandler.InsertMessages("-", "Response LASSIE: " + lassie, "SetAppStage", true);
if (lassie != null && lassie.SessionID != null)
StaticMembers.StaticObjects.LoginResponseObject.SessionID = lassie.SessionID;
This function is called on a button click:
var returnValue = await SDI.CRONDesktopClient.Classes.StaticMembers.StaticObjects.DatabaseCommunication.SetAppStage((int)SDI.IShared.Enumerators.RONNA.Menu.ApplicationStageEnum.NEW_PLAN);
if (returnValue != null && returnValue.SessionID != null)
Now, in my development environment (Windows 8.1 x64, VS 2013) this works fine. Also, when I build the project and execute it on Windows 7 x64 it also works fine. No errors.
But, when I deploy the project on Windows 10, I get the error in the Title. Now, using Google Postman I can confirm that the endpoint in question returns expected values. Also, from the application itself I can login successfully, but after login, when the
application calls the above function, it returns that error.
I am really lost, because I see no obvious reason for it not to work. Maybe someone has some pointers?
Aug 22, 2016 03:04 AM|Yohann Lu|LINK
From your description, you will have an error on Http Client - Task was canceled when you run your application on Windows 10.
You can try to check the following options.
1. Something called Cancel() on the CancellationTokenSource associated with the cancellation token before the task completed.
2. The request timed out. didn't complete within the timespan you specified on HttpClient.Timeout.
As far as I know, the default HttpClient.Timeout value is 100 seconds (00:01:40). If you do a timestamp in your catch block you will notice that tasks begin to get canceled at exactly that time.
3. HttpClient is an async-only library; you may have a deadlock situation. I suggest getting rid of all .Results and .Wait()s and write everything asynchronously, using async/await.