62,046
社区成员
发帖
与我相关
我的任务
分享
Task.Factory.StartNew(() =>
{
string path = ".\\private$\\" + Configurations.MSMQReceivePath;
try
{
if (MessageQueue.Exists(path))
{
MessageQueue queue = new MessageQueue(path);
queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
while (true)
{
try
{
Logger.Debug("准备获取一条消息 " + Thread.CurrentThread.ManagedThreadId + "时间:" + DateTime.Now);
var message = queue.Receive(MessageQueueTransactionType.Single);
Logger.Debug("获取一条消息 " + Thread.CurrentThread.ManagedThreadId + "时间:"+DateTime.Now);
IWeixinService weixinService = MefDependencyResolver.Current.GetService<IWeixinService>();
weixinService.AcceptWeixinPushMessage((string)message.Body);
}
catch(Exception ex)
{
Logger.Error("Failed to process weixin push message", ex);
}
Thread.Sleep(5);
}
}
}
catch (Exception ex)
{
Logger.Error("Failed to start MSMQ task", ex);
}
});