Stop all actions of app after closing

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 608 Views - Last Post: 27 February 2012 - 09:38 AM Rate Topic: -----

#1 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Stop all actions of app after closing

Posted 24 February 2012 - 09:10 AM

Hi I have just published an app i was making. However whilst testing i noticed when i close the app using the Exit button which contains the code below

Application.Exit()


The app still runs, not on my screen it looks like it has close correctly but when i check the task manager to make sure it had stop it was still running. anyone have any ideas what could be the problem. I would post my code however there is way to much to post. Just any ideas that could cause this problem please.

Is This A Good Question/Topic? 0
  • +

Replies To: Stop all actions of app after closing

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6438
  • View blog
  • Posts: 23,432
  • Joined: 12-June 08

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:12 AM

Try "me.close" and see where that gets you.

Some reading on "why".
Was This Post Helpful? 0
  • +
  • -

#3 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:22 AM

That was got to know about me.close and app.Exit. I see why me.close() is best with App.Exit not executing form closing code and so on. However me.close() still did not stop the process in the task manager any other ideas
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6438
  • View blog
  • Posts: 23,432
  • Joined: 12-June 08

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:24 AM

What's your program doing? Are there unclosed threads?
Was This Post Helpful? 0
  • +
  • -

#5 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:28 AM

Yes modi123 there may be unclosed thread i am using multi-threading is there a way to kill all active threads on closing or should i be doing this when i am finished with the thread. However if i wanted to kill the app before i was finish with the active thread. I would still need to kill active threads on closing
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6438
  • View blog
  • Posts: 23,432
  • Joined: 12-June 08

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:32 AM

How are you running your threads? Is there a collection you can poll in the 'closing' event to wait for these threads to stop?
Was This Post Helpful? 0
  • +
  • -

#7 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:35 AM

as far as I know, threads have a method called .Abort
Was This Post Helpful? 0
  • +
  • -

#8 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:35 AM

No there is no poll in a closing event. I know i don't have this as i don't know what it is could you please explain "Is there a collection you can poll in the 'closing' event "


I heard that using .Abort is a bad way to do this as it throws expections but i could be wrong

This post has been edited by m_wylie85: 24 February 2012 - 09:37 AM

Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6438
  • View blog
  • Posts: 23,432
  • Joined: 12-June 08

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:51 AM

Okay.. show me how you are creating your threads.
Was This Post Helpful? 0
  • +
  • -

#10 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Re: Stop all actions of app after closing

Posted 24 February 2012 - 09:58 AM

Ok this code below is the button call:

    Private Sub btnOpenRoyalFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenRoyalFile.Click
        Dim thread As New System.Threading.Thread(AddressOf RoyalRecordSort)
        thread.Start()
    End Sub


Then i have delegate and sub as below:
    Private Delegate Sub DelRoyalPhysicalMerges(ByVal Mystring As String)
    Private Sub SubRoyalPhysicalMerges(ByVal Mystring As String)
        rtbRoyalPhysicalMerge.Text = Mystring
    End Sub


Then i am invoking it as below:

                If rtbRoyalPhysicalMerge.InvokeRequired Then
                    rtbRoyalPhysicalMerge.Invoke(New DelRoyalPhysicalMerges(AddressOf SubRoyalPhysicalMerges), RoyalPhysicalMerges)
                Else
                    rtbRoyalPhysicalMerge.Text = RoyalPhysicalMerges
                End If

Was This Post Helpful? 0
  • +
  • -

#11 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Stop all actions of app after closing

Posted 24 February 2012 - 10:02 AM

Did you tell the thread that it belongs to this process? This is how to do it:

thread.IsBackground = True

Was This Post Helpful? 1
  • +
  • -

#12 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6438
  • View blog
  • Posts: 23,432
  • Joined: 12-June 08

Re: Stop all actions of app after closing

Posted 24 February 2012 - 10:27 AM

That's what I thought you were doing.

Okay, and this might just be my personal control freakness gushing forth, but important and odd objects (like threads) I desire to be able to be polled. That means having a collection (if there are more than one) to fill so I have one spot to look for and not a hope and a prayer that I know what they are doing.

In your case it makes me cringe to see a thread being generated in a button click event and not say added to a list(of) or some collection. Hell when your scope ends for the button event you will never ever have the ability to say "thread.ThreadState = Threading.ThreadState.Running" to see if the bastard is running! Also your user might come down with a case of the clickityitus and jam on that button control like they are trying to stress test their mouse's button. You could have hundreds or thousands of threads running around you don't have access too! EEK!

Example:
'-- global collection
    private _threads As New List(Of Thread)

    Private Sub btnOpenRoyalFile_Click(
        _threads.Add(New System.Threading.Thread(AddressOf SubRoyalPhysicalMerges))
	_threads(_threads.Count - 1).Start()
    End Sub




Now in your closing you can do a myriad of things to wait until you thread closes or kill them off directly.

Example:

    Private Sub Form_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        For Each temp As Thread In _threads
            If temp.ThreadState = ThreadState.Running Then '-- o noes!  mah thread is running!  Let's not close!
                e.Cancel = True
                Exit For
            End If
        Next
    End Sub



So yes.. my theory is threads are like children - you may have created them but damn if you aren't going to take care of them. Except for the ginger ones. Those go to the orphenariums.
Was This Post Helpful? 1
  • +
  • -

#13 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Re: Stop all actions of app after closing

Posted 24 February 2012 - 11:07 AM

Ha Ha Modi true i wonder about double clicking and so (clickityitus) but i am still pretty new to multi-thread thanks for all the help.

Ps (Except for the ginger ones. Those go to the orphenariums. ) made me lol

Thanks again i will try to implement your suggestions and get back to you
Was This Post Helpful? 0
  • +
  • -

#14 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 93
  • View blog
  • Posts: 871
  • Joined: 15-October 10

Re: Stop all actions of app after closing

Posted 27 February 2012 - 08:19 AM

hey i am tring to understand what modi pointed out above i have rewrote some of his ideas and i have done it as so:

    Public Function threadHold()
        _threads.Add(New System.Threading.Thread(AddressOf RoyalRecordSort))
        Return _threads
    End Function
    Private Sub CheckRunningThreads(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        For Each temp As Thread In _threads
            If temp.ThreadState = ThreadState.Running Then '-- o noes!  mah thread is running!  Let's not close!
                e.Cancel = True
                Exit For
            End If
        Next
    End Sub
#Region "Buttons"
    Private Sub btnOpenRoyalFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenRoyalFile.Click
        'Dim thread As New System.Threading.Thread(AddressOf RoyalRecordSort)
        'thread.Start()
        threadHold()
        _threads(_threads.Count - 1).Start()
    End Sub


I took this line out and put it into it's own function:

_threads.Add(New System.Threading.Thread(AddressOf RoyalRecordSort))



i done this because if i left it in the button click i would lose scope by the time i call the for closing event. Now that it is in a function i can keep scope until i need it. So what i am asking is am i going about this in the right way.
Was This Post Helpful? 0
  • +
  • -

#15 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6438
  • View blog
  • Posts: 23,432
  • Joined: 12-June 08

Re: Stop all actions of app after closing

Posted 27 February 2012 - 08:25 AM

Quote

i done this because if i left it in the button click i would lose scope by the time i call the for closing event. Now that it is in a function i can keep scope until i need it. So what i am asking is am i going about this in the right way.


Wait, what? That doesn't make sense.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2