我将使用IBM.XMS库与WebSphereMQ进行通信。在使用同步方法接收消息时,例如:
但是,如果我想使用异步方法:
using (var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{
message = consumer.Receive(1000);
if (message != null)
{
//Do work here
scope.Complete();
}
}
但是,如果我想使用异步方法:
consumer.MessageListener = delegate(IMessage msg)
{
//Do work here
//But where do I put TransactionScope?
};
我无法弄清如何将 MessageListener
回调包装在 TransactionScope
中。
有人知道如何做吗?