WaitForRowsAsync(CancellationToken) Method
Asynchronously waits for new rows to be available in the internal queue of this real-time cursor. The returned
System.Threading.Tasks.Task will also complete if the state of this
RealtimeCursor (see
GetState) changes from
RealtimeCursorState.Subscribed. This method can be called on any thread.
Parameters
- cancellationToken
- A System.Threading.CancellationToken used to control cancellation behavior for the returned task.
Return Value
A
System.Threading.Tasks.Task that will complete once this cursor becomes unsubscribed or new rows are available in the internal queue of this real-time cursor. The returned
System.Boolean value is
false if this cursor is unsubscribed and there are no more rows to be read. Otherwise it's
true.
Explicitly Cancel WaitForRowsAsync
//somewhere in our code we create a CancellationTokenSource
var cancel = new CancellationTokenSource();
//...
//call cancel on the CancellationTokenSource anywhere in
//the add-in, assuming the CancellationTokenSource is in scope
if (SomeConditionForCancel)
cancel.Cancel();//<-- will cancel the token
//Within QueuedTask we are subscribed! streamLayer.Subscribe() or SearchAndSubscribe()
try
{
//TaskCanceledException will be thrown when the token is cancelled
while (await rc.WaitForRowsAsync(cancel.Token))
{
//check for row events
while (rc.MoveNext())
{
using (var row = rc.Current)
{
//etc
}
}
}
}
catch (TaskCanceledException tce)
{
//Handle cancellation as needed
}
cancel.Dispose();
Search And Subscribe With Cancellation
await QueuedTask.Run(async () =>
{
//Recycling cursor - 2nd param "true"
//or streamLayer.Subscribe(qfilter, true) to just subscribe
using (var rc = streamLayer.SearchAndSubscribe(qfilter, true))
{
//auto-cancel after 20 seconds
var cancel = new CancellationTokenSource(new TimeSpan(0, 0, 20));
//catch TaskCanceledException
try
{
while (await rc.WaitForRowsAsync(cancel.Token))
{
//check for row events
while (rc.MoveNext())
{
using (var row = rc.Current)
{
//etc
}
}
}
}
catch (TaskCanceledException tce)
{
//Handle cancellation as needed
}
cancel.Dispose();
}
});
Target Platforms: Windows 11, Windows 10, Windows 8.1
ArcGIS Pro version: 2.4 or higher.