Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. avoid an application closing when calculations are in progress?

avoid an application closing when calculations are in progress?

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bouli
    wrote on last edited by
    #1

    Hello gurus, I'd like to know how to avoid an application closing when calculations are being performed? I tried to trap the Closing event and set the e.Cancel to false, but it quits anyway :( private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_permuting) e.Cancel=!_permuting; } Thanks for the help. There is no spoon.

    E P 2 Replies Last reply
    0
    • B bouli

      Hello gurus, I'd like to know how to avoid an application closing when calculations are being performed? I tried to trap the Closing event and set the e.Cancel to false, but it quits anyway :( private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_permuting) e.Cancel=!_permuting; } Thanks for the help. There is no spoon.

      E Offline
      E Offline
      eggie5
      wrote on last edited by
      #2

      What is "closing" your app? How do you know your catching the right method? What about Application.Exit()???? /\ |_ E X E GG

      1 Reply Last reply
      0
      • B bouli

        Hello gurus, I'd like to know how to avoid an application closing when calculations are being performed? I tried to trap the Closing event and set the e.Cancel to false, but it quits anyway :( private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (_permuting) e.Cancel=!_permuting; } Thanks for the help. There is no spoon.

        P Offline
        P Offline
        Peter Molnar
        wrote on last edited by
        #3

        This is a multithreading issue. 1.Spawn a worker thread with the the long calculation

        Thread m_Thread;
        ...
        m_Thread = new Thread(new ThreadStart(MyLongCalculationFunction));
        m_Thread.Start();

        2.In your Form_Closing handler check the thread state

        if (m_Thread.ThreadState == ThreadState.Running) ...

        If running, dont let the dialog close by giving

        e.Cancel = true;

        Peter Molnar

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups