interrupting a C# method that was called from VBA
I have a lengthy C# calculation invoked from Excel VBA, and I'd like to allow the user to interrupt and abort the calculation with CTRL-C. Can someone suggest a clean technique to handle this ? The C# code is compiled as a com-visible class library and its purpose is purely number crunching.
(Also important that the Excel session not interfere w other tasks if开发者_运维百科 the user has - e.g. gone off to read his mail while waiting).
You could make the call async and use ManualResetEvents from within your C# code to check if you need to stop the calculation or not at certain points in your code. This would require an additional function to be able to set this ManualResetEvent from VBA.
精彩评论