首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows推荐缓存?

问Windows推荐缓存?
EN

Stack Overflow用户
提问于 2013-12-09 13:19:42
回答 1查看 472关注 0票数 2

刚刚创建了一个新的工作者角色来处理来自队列的消息。这方面的默认示例在开头包含以下代码:

代码语言:javascript
复制
// QueueClient is thread-safe. Recommended that you cache 
// rather than recreating it on every request
QueueClient Client;

有人能详细说明这个演示附带的评论吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-09 13:31:52

不要每次都创建新实例。只创建一个实例,并使用它。

代码语言:javascript
复制
//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");
        }
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20471663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档