2013-12-09 14 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