![](/img/trans.png)
[英]How do I pass two similar concrete objects to a method with interface parameters that implement generics in C#?
[英]How do I write an async Update method to pass two parameters using RestSharp?
我正在 Unity 上開發機器人應用程序,我想將兩個參數從我的應用程序連續傳遞給客戶端。 我編寫的代碼導致應用程序運行非常緩慢(大約每 5 秒 1 幀),這一定是我的異步請求的問題,但我不確定問題出在哪里:
async void FixedUpdate ()
{
var client = new RestClient("http://localhost/rw/motionsystem/mechunits/ROB_1?action=mechunit-position");
client.Timeout = -1;
client.CookieContainer = login_cookie;
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded;v=2.0");
request.AddParameter("rob_joint", manualjog);
request.AddParameter("ext_joint", "[0,0,0,0,0,0]");
var restResponse = await client.ExecuteTaskAsync(request);
}
我剛剛用一個專用的 function 和一個 while 循環解決了它。 正如所指出的,問題出在 FixedUpdate 中。 這是工作代碼:
public async void SyncMechanicalUnits() {
var client = new RestClient("http://localhost/rw/motionsystem/mechunits/ROB_1?action=mechunit-position");
client.Timeout = -1;
client.CookieContainer = login_cookie;
while (solveron == true)
{
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded;v=2.0");
request.AddParameter("rob_joint", manualjog);
request.AddParameter("ext_joint", "[0,0,0,0,0,0]");
var restResponse = await client.ExecuteTaskAsync(request);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.