2

キューからのメッセージを処理する新しいワーカー ロールを作成しました。このデフォルトの例には、最初に次のコードが含まれています。

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

そのデモに付属するコメントについて詳しく説明できる人はいますか?

4

1 に答える 1

3

毎回新しいインスタンスを作成しないでください。インスタンスを 1 つだけ作成して使用します。

//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");
        }
    }
}
于 2013-12-09T13:31:52.257 に答える