現在、アプリがサービス バスから非同期メッセージを受信できるようにしようとしています。しかし、例外がスローされることがありますが、それを消す方法や、それが何から発生するのかわかりません。
例外は次のとおりです。
Exception: System.NullReferenceException: Object reference not set to an instance of an object. at GetOffers.DbConnection.processEndReceive(IAsyncResult result);
だから、それが私の IASync メソッドに由来することは知っていますが、それがどこで正しく機能しないのか理解できません。
私の QueueClient conf:
QClient = QueueClient.CreateFromConnectionString(connectionString, queueStr,ReceiveMode.ReceiveAndDelete);
ここで私の両方の IASync メソッド:
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
{
}
}
基本的に、これらのメソッドは、ServiceBus で新しいメッセージを検出するたびにトリガーされます。問題は、 Console.WriteLine("New Message"); を入れたことです。新しいメッセージが検出されたとき、ただし、この CW は 2 回 (またはそれ以上) トリガーされます。
だから2つのことのうちの1つ:私のエラーの原因は何ですか?そして、IAsync メソッドをこのメッセージで一度だけトリガーする方法を教えてください。