473,403 Members | 2,338 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,403 software developers and data experts.

Thread Killing

How do I kill the thread of one button with the clicking of another button?

ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That

End Sub


Thanks,
Michael
Nov 20 '05 #1
10 1392
Cor
Hi,

A little bit pseudo

Private MyThread as system.threading.thread

fucntion start
MyThread = New System.Threading.Thread(AddressMyTreadStart)
MyThread.Priority = Threading.ThreadPriority.Normal
MyThread.Start()

function kill
MyThread.Abort

I hope this helps?

Cor
How do I kill the thread of one button with the clicking of another button?
ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That

End Sub


Thanks,
Michael

Nov 20 '05 #2
"Michael" <IN******@aol.com> schrieb
How do I kill the thread of one button with the clicking of another
button?

ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That

End Sub


Where do you create and start a thread?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
"Armin Zingler" <az*******@freenet.de> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl...
"Michael" <IN******@aol.com> schrieb
How do I kill the thread of one button with the clicking of another
button?

ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That

End Sub


Where do you create and start a thread?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


The code I posed is it. That is all I am doing with threads.
Nov 20 '05 #4
Michael,
The code I posed is it. That is all I am doing with threads.
In that case, both your button event handlers run on the same thread
(because they both are created by the parent form). If btnEnglish_Click
blocks this thread, then you won't be able to click on btnSpanish (unless
there is a call to Application.DoEvents() in btnEnglish_Click).

If you want to interrupt btnEnglish's processing when clicking on
btnSpanish, then you'll have to use some kind of flag in your form class.

I wouldn't recommend doing it like this. If you need to use threads, perhaps
you couls start one when clicking on a button (be careful you don't start it
twice if the user double-clicks on the button). My advice is to learn as
much as possible about threads before doing this - inclucing the pitfalls of
using them with windows forms.

Here's some links that may help:

http://msdn.microsoft.com/library/de...ingExample.asp

http://msdn.microsoft.com/msdnmag/is...t/default.aspx

http://msdn.microsoft.com/library/de...enersample.asp

HTH,
Trev.

"Michael" <IN******@aol.com> wrote in message
news:tU******************@twister.tampabay.rr.com. .. "Armin Zingler" <az*******@freenet.de> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl...
"Michael" <IN******@aol.com> schrieb
How do I kill the thread of one button with the clicking of another
button?

ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That

End Sub


Where do you create and start a thread?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


The code I posed is it. That is all I am doing with threads.

Nov 20 '05 #5
"Michael" <IN******@aol.com> schrieb
How do I kill the thread of one button with the clicking of
another button?

ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That

End Sub


Where do you create and start a thread?


The code I posed is it. That is all I am doing with threads.


You don't create a thread, consequently you can not kill a thread.
--
Armin
Nov 20 '05 #6
* "Michael" <IN******@aol.com> scripsit:
How do I kill the thread of one button with the clicking of another button?

ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That


'btnEnglish' doesn't have its own thread.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7
* "Michael" <IN******@aol.com> scripsit:
System.Threading.Thread.Sleep(200)


This will block the whole UI thread, it doesn't start an other thread.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8
Thanks for the reply,

I do have many Application.DoEvents() in the button event that I want to
stop. They are to update the text box.

Michael

"Trev Hunter" <hu*********@hotmail.com> wrote in message
news:uh**************@TK2MSFTNGP10.phx.gbl...
Michael,
The code I posed is it. That is all I am doing with threads.
In that case, both your button event handlers run on the same thread
(because they both are created by the parent form). If btnEnglish_Click
blocks this thread, then you won't be able to click on btnSpanish (unless
there is a call to Application.DoEvents() in btnEnglish_Click).

If you want to interrupt btnEnglish's processing when clicking on
btnSpanish, then you'll have to use some kind of flag in your form class.

I wouldn't recommend doing it like this. If you need to use threads,

perhaps you couls start one when clicking on a button (be careful you don't start it twice if the user double-clicks on the button). My advice is to learn as
much as possible about threads before doing this - inclucing the pitfalls of using them with windows forms.

Here's some links that may help:

http://msdn.microsoft.com/library/de...ingExample.asp
http://msdn.microsoft.com/msdnmag/is...t/default.aspx

http://msdn.microsoft.com/library/de...enersample.asp
HTH,
Trev.

"Michael" <IN******@aol.com> wrote in message
news:tU******************@twister.tampabay.rr.com. ..
"Armin Zingler" <az*******@freenet.de> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl...
"Michael" <IN******@aol.com> schrieb
> How do I kill the thread of one button with the clicking of another
> button?
>
> ie
> Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles btnEnglish.Click
>
> System.Threading.Thread.Sleep(200)
>
> 'Do This
>
> End Sub
>
>
>
> Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles btnSpanish.Click
>
> 'Kill btnEnghish's Thread
>
> 'Do That
>
> End Sub

Where do you create and start a thread?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


The code I posed is it. That is all I am doing with threads.


Nov 20 '05 #9
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
* "Michael" <IN******@aol.com> scripsit:
How do I kill the thread of one button with the clicking of another button?
ie
Private Sub btnEnglish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEnglish.Click

System.Threading.Thread.Sleep(200)

'Do This

End Sub

Private Sub btnSpanish_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSpanish.Click

'Kill btnEnghish's Thread

'Do That


'btnEnglish' doesn't have its own thread.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Thanks guys,

Let me post more details, maybe that will help.

btnEnglish's click event has text update, then thread sleep, then doevents
then repeats that cycle (but not in a loop) That goes on for a while.

If I click btnSpanish, it puts text in the same text box but does NOT have
thread sleeps and doevents.

If I start btnEnglish, then click btnSpanish, btnSpanish does what it is
supposed to do, but then btnEnglish continues and overwrites btnSpanish's
text. I want to stop btnEnglish from continuing on if btnSpanish gets
clicked mid-btnEnglish's tasks.

Does that make it more clear?

Michael
Nov 20 '05 #10
Cor
Hi Michael,

All processes (subs) are always completly completed, but I think I
understand what you want to do. I think that you need something like this
dirty typed here as pseudo

\\\
Private swEngl as boolean
Private swFirstTime as boolean
///
\\\\
Sub ButtonEnglishpushed
If Not swEngl then
swEngl = True
StartProces
end if
end Sub
Sub ButtonSpanishpushed
If swEng then
swEngl = False
StartProces
end if
end sub
StartProces
if not swfirsttime
dostopcurrentproces
end if
swfirstime = false
if swEngl then
startProcesEnglish
else
startProcesSpanish
end sub
///

I hope this helps?

Cor
btnEnglish's click event has text update, then thread sleep, then doevents
then repeats that cycle (but not in a loop) That goes on for a while.

If I click btnSpanish, it puts text in the same text box but does NOT have
thread sleeps and doevents.

If I start btnEnglish, then click btnSpanish, btnSpanish does what it is
supposed to do, but then btnEnglish continues and overwrites btnSpanish's
text. I want to stop btnEnglish from continuing on if btnSpanish gets
clicked mid-btnEnglish's tasks.

Does that make it more clear?

Michael

Nov 20 '05 #11

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

Similar topics

26
by: djw | last post by:
Hi, Folks- I have a question regarding the "proper" use of try: finally:... Consider some code like this: d = Device.open() try: d.someMethodThatCanRaiseError(...) if SomeCondition: raise...
10
by: Jacek Popławski | last post by:
Hello. I am going to write python script which will read python command from socket, run it and return some values back to socket. My problem is, that I need some timeout. I need to say for...
22
by: nd02tsk | last post by:
Hello! I have a couple of final ( I hope, for your sake ) questions regarding PostgreSQL. I understand PostgreSQL uses processes rather than threads. I found this statement in the archives: ...
8
by: Rob | last post by:
Hello, I've got an issue where a process in a third party application has a dll which while exiting sort of freezes and runs away with processor cycles. i've written a block of code so that I...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() ...
18
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and never return. I am sure it has something to do...
6
by: Roger Heathcote | last post by:
sjdevnull@yahoo.com wrote: <snip> Fair point, but for sub processes that need to be in close contact with the original app, or very small functions that you'd like 100s or 1000s of it seems...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, Is it possible "kill" the thread of Backgroundworker ? In my Dowork event, I have NOT While for do e.Cancel = true, only have a call to external COM. If I want cancel, calling...
6
by: BlueBird | last post by:
Hi, I have a program with a master thread and several slave threads. Whenever an exception occurs, in the master thread or in one of the slave threads, I would like to interrupt all the...
7
by: dmitrey | last post by:
hi all, Is there a better way to kill threading.Thread (running) instance than this one http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496960 (it's all I have found via google). BTW,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.