I have hosted Service Bus project on Azure and woker role is processing all messages. I have noticed that “asyncTask” Wait() not executing always. sometime it is executing there is no guarantee it will work.
I am sure there is no exception and placed the logs before and after it is logging the details but not executing theasyncmethod.
sample code :
CreateInstance methodnot executing (inconsistent behavior)
MyTestClass is not creating instance (inconsistent behavior).
publicoverridevoid Run()
{
Trace.WriteLine("Starting processing of messages");
OnMessageOptions options =newOnMessageOptions();
options.AutoComplete =true;
options.AutoRenewTimeout =TimeSpan.FromMinutes(1);
// Initiates the message pump and callback is invoked for each message that is received, calling close on the client will stop the pump.
Client.OnMessage((receivedMessage) =>
{
try
{
Task.Factory.StartNew(() => longProcess(receivedMessage,ref Processcount, dictionary));
}
catch (Exception ex)
{
logData("Run Expcetion:"+ ex.ToString());
// Handle any message processing specific exceptions here
}
});
}
publicvoid longProcess(BrokeredMessage receivedMessage, refint Processcount,Dictionary<string,string> dictionary)
{
try
{
CreateInstance(dictionary).Wait();
}
catch (Exception ex)
{
logData("Run Expcetion:"+ ex.ToString());
// Handle exception here.
// Log, write to poison message queue etc ...
}
finally
{
}
}
publicstaticasyncTask CreateInstance(Dictionary<string,string> dictionary)
{
logData("CreateInstanceThreadState:"+ Thread.CurrentThread.ThreadState.ToString());
logData("CreateInstanceThreadId:"+ Thread.CurrentThread.ManagedThreadId.ToString());
logData("CreateInstanceThreadIsBackGround:"+ Thread.CurrentThread.IsBackground.ToString());
Console.WriteLine("CreateInstance");
MyTestClass obj =newMyTestClass();
}
Please help me.