私はこれに数日間取り組んでおり、複数のスレッドと BLOB クライアントに関する以前の質問を読み、その提案を実装しました。
問題を以下に要約しました。
エラーは生成されず、threadtestコンテナー (既に存在する) には何も書き込まれません。1 つのブロブが書き込まれ、その後何も書き込まれないことがあります。
Sleep を 1 秒に増やすと、すべて問題ありません。
コードの理由は、Azure の BLOB 書き込み機能のベンチマークを行うことです。(私は現在、1 時間に 700,000 を実行する 8 つのシングルスレッド インスタンスを持っていますが、これを理解できれば、さらに高くできると確信しています)
using System;
using System.Net;
using System.Threading;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.StorageClient;
using System.Threading.Tasks;
namespace ThreadedWriterTest
{
public class WorkerRole : RoleEntryPoint
{
private static CloudStorageAccount storageAccount;
public override void Run()
{
while (true)
{
Thread.Sleep(10);
Task.Factory.StartNew(()=> writeStuff());
}
}
private void writeStuff()
{
CloudBlobClient threadClient = storageAccount.CreateCloudBlobClient();
threadClient.GetBlobReference("threadtest/" + Guid.NewGuid().ToString()).UploadText("Hello " + Guid.NewGuid().ToString());
}
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("XXX"));
return base.OnStart();
}
}
}