MathParser.org-mXparser icon indicating copy to clipboard operation
MathParser.org-mXparser copied to clipboard

(C#) Ability to cancel a single thread with CancellationToken

Open RufRef opened this issue 4 years ago • 3 comments

mXparser.cancelCurrentCalculation() might be useful for simple use cases, but if you are running many calculations on multiple threads; it stops them all.

Please add a CancellationToken parameter to Expression.calculate() so that ONE calculation can be cancelled; not all of the currently-running ones.

Thanks.

RufRef avatar Apr 19 '20 14:04 RufRef

This is certainly good idea, but I need some help in the design. A lot of heavy calculation is done in the final class (java) or sealed class (.NET) using static methods. Take a look on the Calculus examples searching for if (mXparser.isCurrentCalculationCancelled()) return Double.NaN:

  • JAVA: https://github.com/mariuszgromada/MathParser.org-mXparser/blob/master/CURRENT/java/src/org/mariuszgromada/math/mxparser/mathcollection/Calculus.java
  • .NET: https://github.com/mariuszgromada/MathParser.org-mXparser/blob/master/CURRENT/c-sharp/src/org/mariuszgromada/math/mxparser/mathcollection/Calculus.cs

Sending CancellationToken to Expression.calculate() would require strong code refactoring ...

Maybe some solution would be to globally set particular thread id that should be cancelled ...

Let's discuss.

Best regards

mariuszgromada avatar Mar 19 '22 22:03 mariuszgromada

You have to add a CancellationToken in all methods, going all the down the stack. It’s a big change… see this screenshot. Let me know how I can help.

Thanks, Andy

On Sat, Mar 19, 2022 at 6:17 PM Mariusz Gromada @.***> wrote:

This is certainly good idea, but I need some help in the design. A lot of heavy calculation is done in the final class (java) or sealed class (.NET) using static methods. Take a look on the Calculus examples searching for if (mXparser.isCurrentCalculationCancelled()) return Double.NaN:

  • JAVA: https://github.com/mariuszgromada/MathParser.org-mXparser/blob/master/CURRENT/java/src/org/mariuszgromada/math/mxparser/mathcollection/Calculus.java
  • .NET: https://github.com/mariuszgromada/MathParser.org-mXparser/blob/master/CURRENT/c-sharp/src/org/mariuszgromada/math/mxparser/mathcollection/Calculus.cs

Sending CancellationToken to Expression.calculate() would require strong code refactoring ...

Maybe some solution would be to globally set particular thread id that should be cancelled ...

Let's discuss.

Best regards

— Reply to this email directly, view it on GitHub https://github.com/mariuszgromada/MathParser.org-mXparser/issues/206#issuecomment-1073120954, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHHLIKKAM7TQ6TYHTFXJMALVAZHALANCNFSM4MLZRMAQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

RufRef avatar Mar 24 '22 11:03 RufRef

In the next major release I will try to make it happen :-)

mariuszgromada avatar May 24 '22 18:05 mariuszgromada