我在c#中的应用程序出现问题,我每隔20毫秒从互联网上接收数据,我需要处理这些数据并使用已处理的数据发出http post请求,但是请求需要很多比从互联网上接收数据更长,这是我的代码:
//data comes from internet every 20 milliseconds
public static async Task CalculateHp(string data)
{
var datos = JsonConvert.DeserializeObject<DataModel>(data);
datos.hp = datos.rpm * datos.torque / 5252;
datos.now = DateTime.Now;
var jsonArray = new JArray();
var jsonStringObject = JsonConvert.SerializeObject(datos);
jsonArray.Add(JObject.Parse(jsonStringObject));
var jsonStringArray = jsonArray.ToString();
var sw = new Stopwatch();
sw.Start();
using (var client = new HttpClient())
{
var response = await client.PostAsync("https://url", new StringContent(jsonStringArray, Encoding.UTF8, "application/json"));
}
long elapsedMilliseconds = sw.ElapsedMilliseconds;
//the value of elapsedMillisecons is approximately 500 milliseconds
Console.WriteLine(elapsedMilliseconds);
}
有人能给我任何建议或例子吗?
感谢您的帮助