Skip to content

Instantly share code, notes, and snippets.

@stdavis
Created December 15, 2017 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stdavis/78012b026f960c92c9578127d525129a to your computer and use it in GitHub Desktop.
Save stdavis/78012b026f960c92c9578127d525129a to your computer and use it in GitHub Desktop.
SetOnUndone & SetOnRedone - What am I doing wrong?
private void AddSelectedToTemp()
{
QueuedTask.Run(() =>
{
using (FeatureClass tempSegsFC = TempSegmentsLayer.GetFeatureClass())
using (RowCursor segmentsCursor = SegmentsLayer.GetSelection().Search((QueryFilter)null, false))
{
EditOperation operation = new EditOperation();
operation.Name = "add selected to temp segments";
bool newPartCreated = false;
operation.Callback(context =>
{
while (segmentsCursor.MoveNext())
{
string id = GetUSNGID_Line(segmentsCursor.Current);
RowBuffer tempRowBuf = CopyRowValues(segmentsCursor.Current, tempSegsFC);
tempRowBuf["USNG_SEG"] = id;
if (tempSegmentIDs.Contains(id))
{
currentPart++;
tempSegmentIDs.Clear();
newPartCreated = true;
}
tempSegmentIDs.Add(id);
tempRowBuf["RoutePart"] = currentPart;
tempSegsFC.CreateRow(tempRowBuf);
tempRowBuf.Dispose();
}
context.Invalidate(tempSegsFC);
}, tempSegsFC);
if (newPartCreated)
{
// NOT WORKING ref: https://community.esri.com/message/733381-re-examples-for-setonundone-setonredone-setoncomitted?commentID=733381#comment-733381
operation.SetOnUndone(() =>
{
currentPart--;
});
operation.SetOnRedone(() =>
{
currentPart++;
});
}
bool success = operation.Execute();
if (success)
{
SegmentsLayer.ClearSelection();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment