【发布时间】:2016-05-23 10:27:35
【问题描述】:
我已经问过这个问题,但没有得到太多回应,而且我得到的那些也没有解决我的问题。所以在这里我尝试以不同的方式再次询问。
我有一个项目将产品提要文件处理到我的系统中。对于一个特定的提要文件,整个过程大约需要 40-50 分钟。现在我创建了一个WebJob 来处理来自提要的图像,并且我通过创建存储客户端将我的第一个项目中的图片网址发送到WebJob。当我在我的项目中使用它时,它显着增加了处理时间,所以我尝试将它与 Task.Run 一起使用以使用 Fire and Forget 方法,但即使现在整个处理时间仍然约为 2 小时。
这是我如何调用创建存储队列的方法。
if (insertImages)
{
#pragma warning disable 4014
Task.Run(async () => { await new QueueUtility().CreateQueueMessage(picture); }).ConfigureAwait(false);
#pragma warning restore 4014
}
这是我创建队列消息的代码
public async Task CreateQueueMessage(Picture picture)
{
Utility.Log log = new Utility.Log();
await AddQueueMessage(picture.url);
}
public async Task AddQueueMessage(string queueMessage)
{
ServicePointManager.UseNagleAlgorithm = false;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("ImagekWebJobStorage"));
// Create the queue client.
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
// Retrieve a reference to a container.
CloudQueue queue = queueClient.GetQueueReference("imagequeue");
// Create a message and add it to the queue.
CloudQueueMessage message = new CloudQueueMessage(queueMessage);
queue.AddMessage(message);
}
我不明白为什么我的处理时间会增加一倍,也找不到解决方法。任何能帮助我解决这个问题的想法都会非常有帮助。
编辑:
将QueueUtility 转换为静态类,将方法转换为静态方法似乎有所帮助。不知道如何或为什么。
【问题讨论】:
-
添加到队列中是否需要在后台执行如此昂贵的操作?
-
@StefanSteinegger 是的,我的处理时间从 40 分钟左右增加到至少 1.5 小时
标签: c# .net azure azure-storage-queues fire-and-forget