|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Q: Advice on threadsI was wondering if you experts could cast your eyes over the following code and tell me if I'm doing anything obviously wrong. The code works but causes some unexpected things in an application I'm writing e.g. a form I'm setting to be hidden using .Hide is not hidden: Private m_threadProgress As New Thread(AddressOf ProgressForm) ' the next few lines occur in a sub If Me.m_threadProgress.IsAlive = False Then Me.m_threadProgress = New Thread(AddressOf ProgressForm) End If Me.m_threadProgress.Start() ' do some other stuff Me.m_threadProgress.Abort() ' display another form Can you give me any advice as to whether I'm doing this correctly? Thanks in advance G >Can you give me any advice as to whether I'm doing this correctly? Calling Thread.Abort is generally a bad idea. Other than that it'shard to say anything without seeing more of your code. Are you creating or interacting with any UI components from your background thread? Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Hi Mattis
The thread displays a form with some flashing text. I'm using it to show that long calculations are proceeding. You say that Thread.Abort is a bad idea. How should I stop the thread and dispose of it when it is no longer in use? Thanks for your help. Show quoteHide quote "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:%23cGXQbn8GHA.3552@TK2MSFTNGP03.phx.gbl... > >Can you give me any advice as to whether I'm doing this correctly? > > Calling Thread.Abort is generally a bad idea. Other than that it's > hard to say anything without seeing more of your code. Are you > creating or interacting with any UI components from your background > thread? > > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. In the form, create a boolean property to tell the form you are ready for it
to close. Then, where you use the thread.Abort(), simply set this property to true. Inside the form's code, periodically check this flag and exit. Mike Ober. Show quoteHide quote "G .Net" <nodamnspam@email.com> wrote in message news:VOudnQ4VdIh4c6jYRVnygg@pipex.net... > Hi Mattis > > The thread displays a form with some flashing text. I'm using it to show > that long calculations are proceeding. > > You say that Thread.Abort is a bad idea. How should I stop the thread and > dispose of it when it is no longer in use? > > Thanks for your help. > > "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message > news:%23cGXQbn8GHA.3552@TK2MSFTNGP03.phx.gbl... >> >Can you give me any advice as to whether I'm doing this correctly? >> >> Calling Thread.Abort is generally a bad idea. Other than that it's >> hard to say anything without seeing more of your code. Are you >> creating or interacting with any UI components from your background >> thread? >> >> >> Mattias >> >> -- >> Mattias Sjögren [C# MVP] mattias @ mvps.org >> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >> Please reply only to the newsgroup. > > Hi Michael
How can I set the property of the form from the thread? G Show quoteHide quote "Michael D. Ober" <ober***@.alum.mit.edu.nospam> wrote in message news:OViaVZr8GHA.788@TK2MSFTNGP05.phx.gbl... > In the form, create a boolean property to tell the form you are ready for > it to close. Then, where you use the thread.Abort(), simply set this > property to true. Inside the form's code, periodically check this flag > and exit. > > Mike Ober. > > "G .Net" <nodamnspam@email.com> wrote in message > news:VOudnQ4VdIh4c6jYRVnygg@pipex.net... >> Hi Mattis >> >> The thread displays a form with some flashing text. I'm using it to show >> that long calculations are proceeding. >> >> You say that Thread.Abort is a bad idea. How should I stop the thread and >> dispose of it when it is no longer in use? >> >> Thanks for your help. >> >> "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message >> news:%23cGXQbn8GHA.3552@TK2MSFTNGP03.phx.gbl... >>> >Can you give me any advice as to whether I'm doing this correctly? >>> >>> Calling Thread.Abort is generally a bad idea. Other than that it's >>> hard to say anything without seeing more of your code. Are you >>> creating or interacting with any UI components from your background >>> thread? >>> >>> >>> Mattias >>> >>> -- >>> Mattias Sjögren [C# MVP] mattias @ mvps.org >>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >>> Please reply only to the newsgroup. >> >> > > Do you by chance have a form that is opening as a showmodal form in a
different thread? If so, could you lemmi know how u did that. Ive been trying to do something simillar. Miro Show quoteHide quote "G .Net" <nodamnspam@email.com> wrote in message news:VOudnQ4VdIh4c6jYRVnygg@pipex.net... > Hi Mattis > > The thread displays a form with some flashing text. I'm using it to show > that long calculations are proceeding. > > You say that Thread.Abort is a bad idea. How should I stop the thread and > dispose of it when it is no longer in use? > > Thanks for your help. > > "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message > news:%23cGXQbn8GHA.3552@TK2MSFTNGP03.phx.gbl... >> >Can you give me any advice as to whether I'm doing this correctly? >> >> Calling Thread.Abort is generally a bad idea. Other than that it's >> hard to say anything without seeing more of your code. Are you >> creating or interacting with any UI components from your background >> thread? >> >> >> Mattias >> >> -- >> Mattias Sjögren [C# MVP] mattias @ mvps.org >> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >> Please reply only to the newsgroup. > > Hi Miro
In the code I used above, simply have Private Sub ProgressForm() Dim form As MyForm = New MyForm() form.ShowDialog() End Sub However, the problem is how do we close the form succesfully? From what I gather, using Abort is not a good idea; although it does appear that the form is closed in calling it. G Show quoteHide quote "Miro" <miron***@golden.net> wrote in message news:u5k47fr8GHA.4808@TK2MSFTNGP03.phx.gbl... > Do you by chance have a form that is opening as a showmodal form in a > different thread? > > If so, could you lemmi know how u did that. Ive been trying to do > something simillar. > > Miro > > "G .Net" <nodamnspam@email.com> wrote in message > news:VOudnQ4VdIh4c6jYRVnygg@pipex.net... >> Hi Mattis >> >> The thread displays a form with some flashing text. I'm using it to show >> that long calculations are proceeding. >> >> You say that Thread.Abort is a bad idea. How should I stop the thread and >> dispose of it when it is no longer in use? >> >> Thanks for your help. >> >> "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message >> news:%23cGXQbn8GHA.3552@TK2MSFTNGP03.phx.gbl... >>> >Can you give me any advice as to whether I'm doing this correctly? >>> >>> Calling Thread.Abort is generally a bad idea. Other than that it's >>> hard to say anything without seeing more of your code. Are you >>> creating or interacting with any UI components from your background >>> thread? >>> >>> >>> Mattias >>> >>> -- >>> Mattias Sjögren [C# MVP] mattias @ mvps.org >>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >>> Please reply only to the newsgroup. >> >> > > Generally, I would have the thread do the work and have the flashing dialog
in my main UI thread. You can have the thread trigger an event that you catch in the UI thread when the worker thread is done calculating then close the dialog by calling a method from the finished event that the worker thread fired. -- Show quoteHide quoteDennis in Houston "G .Net" wrote: > Hi Miro > > In the code I used above, simply have > > Private Sub ProgressForm() > Dim form As MyForm = New MyForm() > form.ShowDialog() > End Sub > > However, the problem is how do we close the form succesfully? From what I > gather, using Abort is not a good idea; although it does appear that the > form is closed in calling it. > > G > > "Miro" <miron***@golden.net> wrote in message > news:u5k47fr8GHA.4808@TK2MSFTNGP03.phx.gbl... > > Do you by chance have a form that is opening as a showmodal form in a > > different thread? > > > > If so, could you lemmi know how u did that. Ive been trying to do > > something simillar. > > > > Miro > > > > "G .Net" <nodamnspam@email.com> wrote in message > > news:VOudnQ4VdIh4c6jYRVnygg@pipex.net... > >> Hi Mattis > >> > >> The thread displays a form with some flashing text. I'm using it to show > >> that long calculations are proceeding. > >> > >> You say that Thread.Abort is a bad idea. How should I stop the thread and > >> dispose of it when it is no longer in use? > >> > >> Thanks for your help. > >> > >> "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message > >> news:%23cGXQbn8GHA.3552@TK2MSFTNGP03.phx.gbl... > >>> >Can you give me any advice as to whether I'm doing this correctly? > >>> > >>> Calling Thread.Abort is generally a bad idea. Other than that it's > >>> hard to say anything without seeing more of your code. Are you > >>> creating or interacting with any UI components from your background > >>> thread? > >>> > >>> > >>> Mattias > >>> > >>> -- > >>> Mattias Sjögren [C# MVP] mattias @ mvps.org > >>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > >>> Please reply only to the newsgroup. > >> > >> > > > > > > > Yeah Im trying something similar but once all my calculations are done, I
put a command button "close" that shows up that the user selects to continue. -User wanted to know it was complete instead of it dissapearing automatically. I will try to close it automatically and see what I find too. Ill be hitting my code this weekend agian. Miro Show quoteHide quote "G .Net" <nodamnspam@email.com> wrote in message news:EfWdnTLnOKJRxKvYnZ2dnUVZ8qudnZ2d@pipex.net... > Hi Miro > > In the code I used above, simply have > > Private Sub ProgressForm() > Dim form As MyForm = New MyForm() > form.ShowDialog() > End Sub > > However, the problem is how do we close the form succesfully? From what I > gather, using Abort is not a good idea; although it does appear that the > form is closed in calling it. > > G > > "Miro" <miron***@golden.net> wrote in message > news:u5k47fr8GHA.4808@TK2MSFTNGP03.phx.gbl... >> Do you by chance have a form that is opening as a showmodal form in a >> different thread? >> >> If so, could you lemmi know how u did that. Ive been trying to do >> something simillar. >> >> Miro >> >> "G .Net" <nodamnspam@email.com> wrote in message >> news:VOudnQ4VdIh4c6jYRVnygg@pipex.net... >>> Hi Mattis >>> >>> The thread displays a form with some flashing text. I'm using it to show >>> that long calculations are proceeding. >>> >>> You say that Thread.Abort is a bad idea. How should I stop the thread >>> and dispose of it when it is no longer in use? >>> >>> Thanks for your help. >>> >>> "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message >>> news:%23cGXQbn8GHA.3552@TK2MSFTNGP03.phx.gbl... >>>> >Can you give me any advice as to whether I'm doing this correctly? >>>> >>>> Calling Thread.Abort is generally a bad idea. Other than that it's >>>> hard to say anything without seeing more of your code. Are you >>>> creating or interacting with any UI components from your background >>>> thread? >>>> >>>> >>>> Mattias >>>> >>>> -- >>>> Mattias Sjögren [C# MVP] mattias @ mvps.org >>>> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com >>>> Please reply only to the newsgroup. >>> >>> >> >> > >
Recognizing if SQL Server is installed (and what version)
Installed, but where is it? Full qual. name of current method open source .NET search engine? DateTime Field Passing parameters in VB 2005!! Showing Form in New Thread? db connections and text boxes Uninstall a device Split monitor screen into multiple windows |
|||||||||||||||||||||||