1
我有一個系統,只是去服務器和檢索一些文本,以最大限度地提高性能我想一次發送多個請求。代碼如下所示:延遲分配的變量參考
var okButton.Text = TextSystem.Get("ok",language);
但是它允許讓TextSystem在任何地方的代碼調用它與其他代碼以及混合。因此,如果開發人員在使用系統之前必須預先加載所有內容,那麼開發人員有點難以使用該系統。
所以我wounder,如果有可能的
-
當有TextSystem呼叫
- 總結所有的請求到一個大的後10毫秒
- 延遲值賦值給okButton
- 啓動一個新的線程直到接收到響應
我想是這樣的:
var okButton1.Text = TextSystem.Get("ok1",language); // Start thread X and buffer the
// request
var okButton2.Text = TextSystem.Get("ok2",language); // Add ok2 to the request buffer
FinanceCall(); // Execute this call, oh 10ms has passed since thread X started
// send the request with ok1 and ok2 to remote server.
// The server has respond, change the value for okButton1.Text and okButton2.Text.
var okButton3.Text = TextSystem.Get("ok3",language); // Start thread Y and do the same..
此代碼將在ASP.NET中執行,因此我關心的是okButton1.Text在頁面呈現之前設置。我在想如果一些異步/等待的方法可行,但我想就如何解決這個問題提供一些意見。