使用以下代码创建一个控制台应用程序并将任务计划为1分钟,它可以正常工作。我想知道这种方法是正确的还是需要改变这种方法?
public void ReadMessageTest(MessageQueue messageQueue)
{
messageQueue.Formatter =
new ActiveXMessageFormatter();
var receivedMessage = messageQueue.Receive(); // Read meassage from msmq
var messageContents = receivedMessage == null ?
"0" : receivedMessage.Body.ToString();
if (!string.IsNullOrEmpty(messageContents) && messageContents != "0")
{
string strpath = @"S:\msmqPath\Test.txt";
try
{
File.AppendAllText(strpath, messageContents + Environment.NewLine);
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadKey();
}
}
}