PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Q: Advice on threads
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Q: Advice on threads
![]() |
Q: Advice on threads |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi Everybody
I 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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
>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. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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. > > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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. > > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Hi Michael
How can I set the property of the form from the thread? G "Michael D. Ober" <obermd.@.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. >> >> > > |
|
|
|
#7 |
|
Guest
Posts: n/a
|
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" <mironagy@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. >> >> > > |
|
|
|
#8 |
|
Guest
Posts: n/a
|
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. -- Dennis 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" <mironagy@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. > >> > >> > > > > > > > |
|
|
|
#9 |
|
Guest
Posts: n/a
|
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 "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" <mironagy@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. >>> >>> >> >> > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

