当我尝试在一个查询下执行两个查询时,我收到此错误 postasync调用。我已经为每个执行查询使用了parallel。
这是执行异步方法的代码:
Parallel.ForEach(commands, c =>
{
using (ConnectionManager connectionMetaData = new ConnectionManager())
{
connectionMetaData.Open(this.settings.ConnectionString);
AdomdCommand command = new AdomdCommand(c.Value, connectionMetaData.Connection);
command.CommandTimeout = timeOut;
result.Add(c.Key, Cube.ConvertCellSetToDataTable(command.ExecuteCellSet()));
command.Dispose();
Thread.Sleep(150);
}
});
API调用代码:
using (HttpClient client = new HttpClient(handler))
{
client.BaseAddress = new Uri(BaseAddress);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.Timeout.Add(new TimeSpan(1, 0, 0));
MediaTypeFormatter jsonFormatter = new JsonMediaTypeFormatter();
HttpContent content = new ObjectContent<dynamic>(Content, jsonFormatter);
try
{
HttpResponseMessage response = client.PostAsync(ConfigurationManager.AppSettings[Report + "RequestURI"] + Action, content).Result;
if (response.IsSuccessStatusCode)
{
var data = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<T>(data);
}
else
throw new Exception();
}
catch (AggregateException ex)
{
throw ex;
}
}