Half-Shot / matrix-dotnet-sdk

A matrix client library in .NET (C#)
MIT License
62 stars 24 forks source link

httpclient.GetAsync issue when using UWP #13

Open ccarlo88 opened 4 years ago

ccarlo88 commented 4 years ago

Hello!

First, congrats for the .NET API for Matrix! It worked really well with the Console example and is nice to have a SDK developed in .NET. I was making some testes with the sdk and when using UWP it hangs out here:

public MatrixRequestError Get (string apiPath, bool authenticate, out JToken result) { apiPath = GetPath (apiPath,authenticate); Task task = client.GetAsync(apiPath); //Here more exactly var res = RequestWrap(task); res.Wait(); result = res.Result.result; return res.Result.error; }

The GetAsync function will never return.... and it will hang everything around after that. The reason is explained here: https://stackoverflow.com/questions/10343632/httpclient-getasync-never-returns-when-using-await-async/10351400#10351400

I looked around the code and one (not nice) solution would be immediately after each Async httpclient task like GetAsync/PostAsync, to call task.Wait(). Of course if you make Async methods you could use the await keyword with the async methods when calling them.

I didn't implement it because I think you know better than I what to do in the SDK and you know Matrix/Synapse much much better than I. Keep on the good job and please don't let me alone in the .NET! 😄

qwetboy10 commented 4 years ago

I had the same problem with WPF. You can get around this issue by creating a new thread, and doing all Matrix stuff on that thread, but that is a bit of a hack. I think the only real solution to this problem is just refactoring everything to async.