简体   繁体   English

Windows Azure QueueClient建议使用缓存吗?

[英]Windows Azure QueueClient recommended cache?

Just created a new worker role to process messages coming from queue. 刚刚创建了一个新的工作角色来处理来自队列的消息。 The default example for this include the following code at the beginning: 为此的默认示例在开头包括以下代码:

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

Can anyone elaborate on the comment that comes with that demo? 谁能详细说明该演示随附的评论?

don't create new instances every time. 不要每次都创建新实例。 Create just one instance, and use it. 仅创建一个实例,然后使用它。

//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");
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM