Stop function execution

Hi,
I am developing a small program that resizes one or more images at the same time.  I want to implement a function that allows users to stop the program when it is processing images by clicking a "Cancel" Button. But I don't know how to do that properly. Can anyone help me
   Thanks
    Ran



Answer this question

Stop function execution

  • Harald Köstinger

    Hi,

    You can do that by creating a thread that does your image processing. You can then provide a cancel button which just kills the thread that you have started...





    cheers,

    Paul June A. Domag


  • raj4work

    Thanks a lot. I will try it

  • Al_at_Uni

    Hello.

    Have a look at BackgroundWorker. Create a loop in it's executing method which checks its "Cancelled" property, and if not set, resizes the image and shows the progress to the user. You should not kill the thread on cancel if you want to complete the operation of resizing the current image before stopping.

    Checklist: On BackgroundWorker you should implement all three events and set propertire: WorkerReportsProgress and WorkerSupportsCancellation. You should cancel the thread upon program exit (maybe call the same method as your cancelevent calls )

    Do not alter any controls from within your executing (DoWork) method. You have the ProgressChanged event for that.

    Happy threading.



  • hallem

    Also if you don't want to use background worker. Set the threads you start to Thread.BackGround = true;  This may or may not work though.  But using BackgroundWorker is probably better cause thats what microsoft recommends.
  • RoninBraenk

    www.inklass.com/imageresizerv2.zip

    Check the source on that for background threading for image resizing.  It's VERY old, and needs a lot more work that I just don't care to spend on it.  However, it does effectively start/stop, and all that with a behind the scenes thread.


  • Paul Siermann

    I tried threading but it was unsuccessful. The program stopped and seemed not to respond to any action. That was may be something with my implementation of threading. I may try again.
    Thank you very much.
      Ran

  • Stop function execution