none
Cancelling dll call from VB.net RRS feed

  • Question

  • Hello,

     

    I have a C++ dll that's called from a VB.net program. The dll performs a certain amount of calculations in a loop based on the input files that the VB.net program generates. Sometimes the dll can run for a long time and I am trying to implement a cancel feature so that the call to the dll be cancelled.


    The dll is called in by a background worker in vb.net and from what I got from a number of forums is that the cancel button on the form can make a function call to the C++ dll and set a global variable in the C++ dll to a cancel flag and somewhere in my program I can periodically check for this flag. If this flag is true, i can safely delete all memory and return back to the calling vb.net program without completing the calculation.

    I am not sure if this is a correct way to do it? Also would cancelling the dll call from vb.net also release the memory allocated by the dll?

     

    Thanks!

    Friday, October 21, 2011 12:10 PM

Answers

  • May I know how do you load the C++ dll. 

    I think you can dispose it. You can load the dll in a new Appdomain, when detecting the flag to close it, you can dispose objects created in this appdomian and unload the appdomian.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Monday, October 31, 2011 6:05 AM
    Tuesday, October 25, 2011 8:12 AM

All replies

  • Everything you describe is coded in your C++ dll except for the button to call the cancel routine in the dll. You should post to the C++ forum.
    Friday, October 21, 2011 3:45 PM
  • I will do that. Thanks!
    Friday, October 21, 2011 7:08 PM
  • May I know how do you load the C++ dll. 

    I think you can dispose it. You can load the dll in a new Appdomain, when detecting the flag to close it, you can dispose objects created in this appdomian and unload the appdomian.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Monday, October 31, 2011 6:05 AM
    Tuesday, October 25, 2011 8:12 AM