If you don't set a timeout on the cursor then that's pretty much all you can do, as long as the MoveNext
method doesn't accept a CancellationToken
.
Just dispose of the enumerator, catch the ObjectDisposedException
and move on.
I have a solution example for a similar case here. Which in this case would be:
try
{
using(enumerator.CreateTimeoutScope(TimeSpan.FromHours(1)))
{
while(true)
{
if(enumerator.MoveNext())
{
//process the message here
}
}
}
}
catch (ObjectDisposedException)
{
}