내 서비스가 내 서비스 버스에서 비동기 적으로 메시지를 수신 할 수있게하려고하고 있습니다. 하지만 가끔 예외가 던지기 때문에 그걸 어떻게 사라지게 만들 수 있는지 또는 그 원인이 무엇인지 모릅니다.서비스 버스 IAsyncResult
다음은 예외입니다 :
Exception: System.NullReferenceException: Object reference not set to an instance of an object. at GetOffers.DbConnection.processEndReceive(IAsyncResult result);
그래서, 나는 그것이 내 IASync 방법에서 오는 알고 있지만, 나는 그것이 제대로 작동하지 않는 경우 이해할 수 아니에요.
내 QueueClient의 conf : 여기 내 두 IASync 방법
QClient = QueueClient.CreateFromConnectionString(connectionString, queueStr,ReceiveMode.ReceiveAndDelete);
:
void processEndReceive(IAsyncResult result)
{
try
{
QueueClient qc = result.AsyncState as QueueClient;
BrokeredMessage message = qc.EndReceive(result);
ForexData data = new ForexData();
var newtrade = new Trade(data.OfferId, message.Properties["login"].ToString(), message.Properties["amount"].ToString(), message.Properties["instr"].ToString(), message.Properties["type"].ToString(), data.CreationDate, message.Properties["mode"].ToString(), message.Properties["accountID"].ToString(), message.Properties["idTrade"].ToString());
//Static Variable for the WHERE (sql) in ResponseListener Line 215.
idtradetemp = message.Properties["idTrade"].ToString();
Console.WriteLine("Received message " + message.Label);
if (newtrade != null)
{
try
{
newtrades.Add(newtrade);
}
catch
{
Console.WriteLine("Une erreur est survenue lors l'ajout du message dans la liste 'newtrades'");
}
Console.WriteLine("Received Delete: " + DateTime.Now);
}
}
catch (Exception e)
{
Console.WriteLine(string.Format("Exception: {0}", e.ToString()));
TextWriter tw = new StreamWriter("logServiceBus.txt", true);
tw.WriteLine("Program terminated on " + DateTime.Now);
tw.WriteLine("------------------------------------");
tw.WriteLine(string.Format("Exception: {0}", e.ToString()));
tw.WriteLine("------------------------------------");
tw.Close();
}
}
void processEndComplete(IAsyncResult result)
{
try
{
BrokeredMessage m = result.AsyncState as BrokeredMessage;
m.EndComplete(result);
Console.WriteLine("Completed message " + m.Label);
}
catch
{
}
}
Basicaly 그 방법은 자신이 ServiceBus에 새 메시지를 감지 트리거마다입니다. 문제는, Console.WriteLine ("New Message"); 새 메시지가 감지되었지만이 CW는 2 번 (또는 그 이상) 트리거됩니다.
그래서 두 가지 중 하나 : 무엇이 오류입니까? 그리고 어떻게하면이 메시지에 대해 한 번 트리거되도록 IAsync 메서드를 만들 수 있습니까?
내가 살펴볼 것입니다. 감사. – Shuiei