相关疑难解决方法(0)

Azure表存储返回400 Bad Request

我在调试模式下运行它,并附上一个包含异常细节的图像.我怎么知道出了什么问题?我试图在表格中插入数据.天蓝不能给我更多细节?

Obs:存储在Windows Azure上而不在我的机器上.表已创建,但插入数据时出现此错误

在此输入图像描述

// Retrieve the storage account from the connection string.
Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=***;AccountKey=***");

// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

// Create the table if it doesn't exist.
CloudTable table = tableClient.GetTableReference("EmployeeOnlineHistory");
table.CreateIfNotExists();
Run Code Online (Sandbox Code Playgroud)

这是插入代码:

public static void SetStatus(Employee e, bool value)
{
    try
    {
        // Retrieve the storage account from the connection string.
        Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=###;AccountKey=###");

        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

        // Create the CloudTable object that represents the "people" …
Run Code Online (Sandbox Code Playgroud)

c# exception azure azure-table-storage

111
推荐指数
5
解决办法
6万
查看次数

foreach标识符和闭包

在以下两个片段中,第一个是安全的还是你必须做第二个?

安全我的意思是每个线程保证从创建线程的相同循环迭代中调用Foo上的方法?

或者你必须将引用复制到一个新的变量"local"到循环的每次迭代?

var threads = new List<Thread>();
foreach (Foo f in ListOfFoo)
{      
    Thread thread = new Thread(() => f.DoSomething());
    threads.Add(thread);
    thread.Start();
}
Run Code Online (Sandbox Code Playgroud)

-

var threads = new List<Thread>();
foreach (Foo f in ListOfFoo)
{      
    Foo f2 = f;
    Thread thread = new Thread(() => f2.DoSomething());
    threads.Add(thread);
    thread.Start();
}
Run Code Online (Sandbox Code Playgroud)

更新:正如Jon Skeet的回答所指出的,这与线程没有任何关系.

c# closures enumeration

78
推荐指数
3
解决办法
1万
查看次数

从性能角度创建CloudStorageAccount或CloudBlobClient实例的成本有多高?

我是否应该在每次想要从存储中获取blob时创建CloudStorageAccount和CloudBlobClient实例?例如,我实现了自定义虚拟路径提供程序以使用blob存储.什么是最好的设计解决方案:创建CloudStorageAccount和CloudBlobClient情况下,一次作为我的自定义虚拟路径提供的私有字段,或使用静态的效用,创造CloudStorageAccount和CloudBlobClient实例(共享)方法,我想从一个blob每次存储?从性能的角度来看它有多贵?

performance azure

20
推荐指数
1
解决办法
3844
查看次数

Azure存储Blob类型(CloudBlobContainer,CloudBlobClient等)和线程安全

我正在开发一个天蓝色的应用程序,它需要在某个时刻上传(下载)大量的小blob到一个容器(超过1k blob,每个不到1 Mb).为了加快这个过程,我想使用多个线程来上传(下载)blob.

这是我用来上传单个blob的例程:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = 
    blobClient.GetContainerReference(ContainerName);
blobContainer.CreateIfNotExist();

CloudBlob blob = blobContainer.GetBlobReference(Id);
blob.UploadByteArray(Data);
Run Code Online (Sandbox Code Playgroud)

对于上面代码中使用的每种类型,MSDN说如下:

此类型的任何公共静态(在Visual Basic中为Shared)成员都是线程安全的.任何实例成员都不保证是线程安全的.

这是否意味着我需要在每个线程中执行以下代码?或者也许我只能执行一次并在不同的线程之间共享CloudBlobContainer的单个实例?

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = 
    blobClient.GetContainerReference(ContainerName);
Run Code Online (Sandbox Code Playgroud)

我很乐意在不同的线程中使用单个CloudBlobContainer实例,否则会严重降低整个上传(下载)过程的速度.

blob thread-safety azure azure-storage azure-storage-blobs

7
推荐指数
1
解决办法
3678
查看次数