473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Q: Advice on threads

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


Oct 17 '06 #1
8 976
>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.
Oct 18 '06 #2
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" <ma********************@mvps.orgwrote in message
news:%2****************@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.

Oct 18 '06 #3
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" <no********@email.comwrote in message
news:VO********************@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" <ma********************@mvps.orgwrote in message
news:%2****************@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.


Oct 18 '06 #4
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" <no********@email.comwrote in message
news:VO********************@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" <ma********************@mvps.orgwrote in message
news:%2****************@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.


Oct 18 '06 #5
Hi Michael

How can I set the property of the form from the thread?

G

"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:OV*************@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" <no********@email.comwrote in message
news:VO********************@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" <ma********************@mvps.orgwrote in message
news:%2****************@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.



Oct 18 '06 #6
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" <mi******@golden.netwrote in message
news:u5**************@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" <no********@email.comwrote in message
news:VO********************@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" <ma********************@mvps.orgwrote in message
news:%2****************@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.



Oct 18 '06 #7
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" <mi******@golden.netwrote in message
news:u5**************@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" <no********@email.comwrote in message
news:VO********************@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" <ma********************@mvps.orgwrote in message
news:%2****************@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.



Oct 18 '06 #8
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" <no********@email.comwrote in message
news:Ef******************************@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" <mi******@golden.netwrote in message
news:u5**************@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" <no********@email.comwrote in message
news:VO********************@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" <ma********************@mvps.orgwrote in message
news:%2****************@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.




Oct 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Stokes | last post by:
Hi there, I wanted a bit of advice on a program (a prototype) that I am trying to write that uses threads. I will outline what I am attempting to do, and if anyone has any advice on the way I...
1
by: vpr | last post by:
Hi Guys I have a question re. socketserver and wx. I've written a p2p program using socketserver that's nice and quick. I'd like to give the user a tray applet (part of the p2p service) that...
5
by: Calimero | last post by:
I have to write a middleware that could be see as a very specialized Web server (based on threads and sockets) I hesitate between C++ (speed) and C# (more elegant) What is the performance penalty...
8
by: Cider123 | last post by:
I ran into a situation where my Window Service had to process 100,000+ files, when I first noticed I needed to tweak various routines. Everything runs fine, but here's what I ran into: In the...
5
by: Ekempd | last post by:
Hi I need some advice about this situation an how I'm current handling it I hava a ASP.NET solution that in some point start multiples lenghty verification agains diferent databases, my big...
6
by: frizzle | last post by:
Hi there, I'm going to build a simple forum in mySQL. I've thought about it for a while now, but still can't figure it out completely: If i have say 5 main categories, One has 5...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
4
by: Ben Fidge | last post by:
My application uses a singleton static class for writing entries to a log file. The location and name of the log-file is read from web.config each time an entry is written, but has the current date...
13
by: Ramon F Herrera | last post by:
My goal is to write a studio-type application which will initially run on Windows, but I would like it to run on other platforms with minimum efforts. I have made the decision to go with C++. ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.