2013-12-09 57 views
2

剛剛創建了一個新的輔助角色來處理來自隊列的消息。此默認示例包括以下代碼開頭:Windows Azure QueueClient建議緩存?

// QueueClient is thread-safe. Recommended that you cache 
// rather than recreating it on every request 
QueueClient Client; 

任何人都可以詳細說明該演示附帶的註釋嗎?

回答

3

不會每次都創建新的實例。創建一個實例,並使用它。

//don't this 
public class WorkerRole : RoleEntryPoint 
{ 
    public override void Run() 
    { 
     // This is a sample worker implementation. Replace with your logic. 
     Trace.TraceInformation("WorkerRole1 entry point called", "Information"); 

     while (true) 
     { 
      QueueClient Client = new QueueClient(); 
      Thread.Sleep(10000); 
      Trace.TraceInformation("Working", "Information"); 
     } 
    } 
} 

//use this 
public class WorkerRole : RoleEntryPoint 
{ 
    public override void Run() 
    { 
     // This is a sample worker implementation. Replace with your logic. 
     Trace.TraceInformation("WorkerRole1 entry point called", "Information"); 

     QueueClient client = new QueueClient(); 

     while (true) 
     { 
      //client.... 
      Thread.Sleep(10000); 
      Trace.TraceInformation("Working", "Information"); 
     } 
    } 
} 
+0

奇怪 - 這就是他們如何開箱即用+這個評論......所以我猜我很好。謝謝。 – developer82