gpt4 book ai didi

c# - 更新云队列中的消息内容时出现异常

转载 作者:行者123 更新时间:2023-12-03 06:05:03 24 4
gpt4 key购买 nike

我在尝试更新云队列上的消息时遇到异常。

异常(exception)情况是:

System.ArgumentNullException was unhandled
Message=Value cannot be null.
Parameter name: messageId
Source=Microsoft.WindowsAzure.StorageClient
ParamName=messageId
StackTrace:
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImplWithRetry(Func`1 impl, RetryPolicy policy)
at Microsoft.WindowsAzure.StorageClient.CloudQueue.UpdateMessage(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFields)
at WorkerRole.WorkerRole.DoTask(Task task) in C:\Users\ALICE\Desktop\Diplloma\AG - Copy\AzureGrid\WorkerRole\WorkerRole.cs:line 133
at WorkerRole.WorkerRole.Run() in C:\Users\ALICE\Desktop\Diplloma\AG - Copy\AzureGrid\WorkerRole\WorkerRole.cs:line 51
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRole()
at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<StartRole>b__1()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

我的代码是:

private void DoTask(Task task)
{
CloudQueueMessage resultsMessage;

// Queue a status message to indicate this worker is starting the task.
task.TaskStatus = Task.Status.Running;
task.Worker = System.Net.Dns.GetHostName();
resultsMessage = task.Message;
ResultsQueue.UpdateMessage(resultsMessage, TimeSpan.FromSeconds(QueueTimeout), MessageUpdateFields.Content | MessageUpdateFields.Visibility);


Trace.WriteLine("Executing task " + task.TaskId.ToString() + " for job " + task.JobId + ", project " + task.ProjectName,"Information");

using (GridWorker gridWorker = new AppWorker())
{
gridWorker.Execute(task);
}

// Queue results.
task.TaskStatus = Task.Status.Complete;
resultsMessage = task.Message;
ResultsQueue.UpdateMessage(resultsMessage, TimeSpan.FromSeconds(QueueTimeout), MessageUpdateFields.Content | MessageUpdateFields.Visibility);
}

这是任务对象的创建方式

public override void Run()
{
CloudQueueMessage taskMessage;
Task task;

// This is a sample worker implementation. Replace with your logic.
Trace.WriteLine("Initializing", "Information");

LoadConfigurationSettings();
OpenQueues();

Trace.WriteLine("Initializing", "Ready for work");

// Work loop. Read a task from the queue. If there is a task, execute it and pass work output to the results queue. Loop.

while (true)
{
taskMessage = TaskQueue.GetMessage(TimeSpan.FromSeconds(QueueTimeout));
//taskMessage = TaskQueue.PeekMessage();

if (taskMessage != null)
{
task = new Task(taskMessage);
DoTask(task);
TaskQueue.DeleteMessage(taskMessage);
}
else
Thread.Sleep(SleepInterval * 1000);
}
}

这是我的第一个应用程序,我不知道该怎么做。

最佳答案

task.Message 从哪里来?之前是从队列中读取的吗? (似乎缺少消息 ID。)

关于c# - 更新云队列中的消息内容时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12239353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com