如何处理PXLongOperation的取消

时间:2017-08-29 02:52:13

标签: acumatica

我的代码中有一个PXLongOperation,我找不到如何知道用户是否取消了操作的方法。

public PXAction<SomeFilter> someUpdate;
        [PXButton(CommitChanges = true)]
        [PXUIField(DisplayName = "Update")]
        public void SomeUpdate()
        {
            if (this.Base.Filter.Current == null)
                throw new PXException("Please choose val.");

            PXLongOperation.StartOperation(this.Base, () =>
                           SomeOperation(this.Base.Filter.Current)                       
            );
        }

private void SomeOperation(SomeFilter filter)
{
   //how to know user cancelled operation or not?
}

2 个答案:

答案 0 :(得分:1)

从一个单独的线程调用委托,如果长操作被取消,该线程将被中止。

答案 1 :(得分:1)

您可以使用PXCustomInfo界面获取PXLongOperation的结果。 SetCustomInfo用于设置回调,PXLongRunStatus包含结果:

PXLongOperation.StartOperation(Base, () =>
{
    PXLongOperation.SetCustomInfo(new PXLongOperationCallback());
    SomeOperation(Base.Filter.Current)
});

public class PXLongOperationCallback : IPXCustomInfo
{
    public void Complete(PXLongRunStatus status, PXGraph graph)
    {
        switch (status)
        {
            case PXLongRunStatus.Aborted:
                break;

            case PXLongRunStatus.Completed:
                break;

            case PXLongRunStatus.InProcess:
                break;

            case PXLongRunStatus.NotExists:
                break;
        }
    }
}

回调操作错误处理的代码示例:

public void Complete(PXLongRunStatus status, PXGraph graph)
{
    if (status == PXLongRunStatus.Completed && graph is MyGraph)
    {
        ((MyGraph)graph).RowSelected.AddHandler<MyDac>((sender, e) =>
        {
            MyDac row = e.Row as MyDac;

            if (row != null)
            {
               sender.RaiseExceptionHandling<MyDac.myField>(row, row.MyField, "Error Message");
            }
        });
    }
}