Вот мой код:
Код: Выделить всё
public class VirtuosoCommunication
{
..
public static VirtuosoCommunication? Create(...)
{
VirtuosoCommunication vc = new VirtuosoCommunication();
// setting private variables for vc
if (!vc.TestRead(log)) return null;
if (!vc.TestWrite(log)) return null;
return vc;
}
private bool TestRead(Log? log)
{
string testGraph = "...";
Task task = LoadGraphFromSparqlRemoteEndpoint(testGraph, log);
Graph? g = task.Result;
return g != null;
}
internal async Task LoadGraphFromSparqlRemoteEndpoint(string graphFullName, Log? log)
{
Uri baseUri = new Uri(_readEndpoint ?? "");
HttpClient client = new HttpClient();
client.BaseAddress = baseUri;
SparqlQueryClient sparqlQueryClient = new SparqlQueryClient(client, baseUri);
Graph result = new Graph();
IGraph? tmp = null;
try
{
while (tmp == null || tmp.Triples.Count == limit)
{
string query = "construct { ?s ?p ?o } FROM where {?s ?p ?o.} OFFSET " + offSet.ToString() + " LIMIT " + limit.ToString();
Task task = sparqlQueryClient.QueryWithResultGraphAsync(query);
tmp = await task.WaitAsync(TimeSpan.FromSeconds(4));
...
}
}
catch (Exception ex) { ... }
return result;
}
Как я уже сказал, тот же асинхронный вызов в тестовой процедуре полностью размещен в MainWindow.xaml.cs работает без проблем, поэтому я думаю, что каким-то образом неправильно использую асинхронный вызов.
Подробнее здесь: https://stackoverflow.com/questions/792 ... -waitasync
Мобильная версия