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. Windows Forms
  4. Run Code/Fire Event After First Event Finishes

Run Code/Fire Event After First Event Finishes

Scheduled Pinned Locked Moved Windows Forms
helpcom
7 Posts 3 Posters 1 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.
  • S Offline
    S Offline
    Stinebaugh
    wrote on last edited by
    #1

    I have a form with an ActiveX control on it. When the disconnect event of the OCX runs, I want to close the form. The problem is, if I call the close command from within the disconnect event, I get an access violation as the form/control is disposed of when the OCX event finishes up.

    OCX Disconnect Event
    {
    Custom EventHandler for OCX Disconnect Event
    {
    Clean up all connections and close form
    {
    Form Close Event
    {
    Form is closed and all controls are disposed of
    {
    }
    }
    }
    }
    Exception thrown as the parent form no longer exists
    }

    I just need to make the Clean up all connections and close form function run after OCX Disconnect Event, but I don't know how or if its possible. Any help or work arounds would be appreciated. Currently, my only work around is basically to leave the parent form open and have the user close it.

    L 1 Reply Last reply
    0
    • S Stinebaugh

      I have a form with an ActiveX control on it. When the disconnect event of the OCX runs, I want to close the form. The problem is, if I call the close command from within the disconnect event, I get an access violation as the form/control is disposed of when the OCX event finishes up.

      OCX Disconnect Event
      {
      Custom EventHandler for OCX Disconnect Event
      {
      Clean up all connections and close form
      {
      Form Close Event
      {
      Form is closed and all controls are disposed of
      {
      }
      }
      }
      }
      Exception thrown as the parent form no longer exists
      }

      I just need to make the Clean up all connections and close form function run after OCX Disconnect Event, but I don't know how or if its possible. Any help or work arounds would be appreciated. Currently, my only work around is basically to leave the parent form open and have the user close it.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      I understand your question like this: the OCX has to be disconnected at some time; the Form should be closed when the OCX disconnect has finished. I know of no perfect solution, this is what I would do: - when you want to disconnect, close the Form; - in FormClosing event, tell the OCX to disconnect and wait; if there is no way to get feedback on the disconnect, the wait would be for a fixed time (e.g. 1 sec); if there is a way, a timeout mechanism should also be provided (it would be unacceptable for a Form not to be closing at all). Hope this helps.

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      S 1 Reply Last reply
      0
      • L Luc Pattyn

        I understand your question like this: the OCX has to be disconnected at some time; the Form should be closed when the OCX disconnect has finished. I know of no perfect solution, this is what I would do: - when you want to disconnect, close the Form; - in FormClosing event, tell the OCX to disconnect and wait; if there is no way to get feedback on the disconnect, the wait would be for a fixed time (e.g. 1 sec); if there is a way, a timeout mechanism should also be provided (it would be unacceptable for a Form not to be closing at all). Hope this helps.

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        S Offline
        S Offline
        Stinebaugh
        wrote on last edited by
        #3

        Guess I forgot to name the type of OCX control. This is an OCX for Remote Desktop/Terminal Services, so the disconnect event if fired whenever they log off, and unfortunetly, I can't capture anything prior to that. I actually do call the disconnect event from the form close, assuming its still connected, and that works. We just prefer to have people log off of there session rather than leaving a disconnected session though.

        L L 2 Replies Last reply
        0
        • S Stinebaugh

          Guess I forgot to name the type of OCX control. This is an OCX for Remote Desktop/Terminal Services, so the disconnect event if fired whenever they log off, and unfortunetly, I can't capture anything prior to that. I actually do call the disconnect event from the form close, assuming its still connected, and that works. We just prefer to have people log off of there session rather than leaving a disconnected session though.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hmm. I guess the event you really want isn't available, so I'd look for a polling scheme then; have a thread or timer periodically try and figure out whether the OCX is still connected, if not, close the Form (or pop up a dialog). :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          1 Reply Last reply
          0
          • S Stinebaugh

            Guess I forgot to name the type of OCX control. This is an OCX for Remote Desktop/Terminal Services, so the disconnect event if fired whenever they log off, and unfortunetly, I can't capture anything prior to that. I actually do call the disconnect event from the form close, assuming its still connected, and that works. We just prefer to have people log off of there session rather than leaving a disconnected session though.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            As an alternative, albeit a messy one; add a timer component to the form, start it from the disconnect, and have the Tick event disable the sender-timer and close the form.

            I are Troll :suss:

            S 1 Reply Last reply
            0
            • L Lost User

              As an alternative, albeit a messy one; add a timer component to the form, start it from the disconnect, and have the Tick event disable the sender-timer and close the form.

              I are Troll :suss:

              S Offline
              S Offline
              Stinebaugh
              wrote on last edited by
              #6

              The Timer method worked great. Thanks for helping me find a work around on this.

              L 1 Reply Last reply
              0
              • S Stinebaugh

                The Timer method worked great. Thanks for helping me find a work around on this.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                You're welcome :)

                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