簡體   English   中英

更新雲隊列中的郵件內容時出現異常

[英]Exception when updating message content in a cloud queue

我在嘗試更新雲隊列上的消息時遇到異常。

例外是:

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。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM