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

Cancelling previous thread

Greetings.
I have a program in VB2008 and I need to execute a thread from differents Subs.
Each time I start the thread I want to cancel the previous.
Here an example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)
  2.            Dim ThreadResults As New Thread(AddressOf ShowResults)
  3.            ThreadResults.Start()
  4. End Sub
  5.  
  6.  
  7. Private Sub ckBoxAllRecords_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  8.            Dim ThreadResults As New Thread(AddressOf ShowResults)
  9.            ThreadResults.Start()
  10. End Sub
I write in a textbox, TextBox_Changed fires, thread spend 4 minutes filling a dataset
I check a checkbox, ckBoxAllRecords_CheckedChanged fires, thread spend 10 seconds filling a dataset.
I dont want anymore the dataset of TextBox_Changed so I want to cancel its filling.
It is possible to do?
Thanks in advance for any reply
Dec 10 '09 #1
2 1586
Plater
7,872 Expert 4TB
If you have an object reference to the Thread you could call the Abort() function, I believe that is frowned upon though. In favor of changing some boolean variable that tells the thread to exit itself.
Dec 10 '09 #2
Thanks for your help.
I resolved my problem creating a thread array.

Expand|Select|Wrap|Line Numbers
  1.         Private ThreadResults(4) As Thread
  2. .
  3. .
  4.         CancelThreads()
  5.         ThreadResults(0) = New Thread(AddressOf Me.ShowResults)
  6.         ThreadResults(0).Start()
  7. .
  8. .
  9. Private Sub CancelThreads()
  10.         For i = 0 To UBound(ThreadResults)
  11.             Try
  12.                 If ThreadResults(i).IsAlive Then
  13.                     ThreadResults(i).Abort()
  14.                 End If
  15.             Catch
  16.             End Try
  17.         Next
  18.  End Sub
  19.  
Dec 11 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Paul THompson | last post by:
I have been working for some time to 1) detect tab and shift tab events 2) control the focus on the basis of these events. I have found that I can do this, but continue to have nagging problems. ...
16
by: Michael Winter | last post by:
Other than throwing an exception during the execution of an object's constructor, is there any way to cancel creation of the object in such a way that it leaves a reference to it null or undefined....
1
by: Sandra | last post by:
Hi All, I am running a VB.NET application which is using ADO to connect to an Oracle 9i database. I have a form which runs a query which can take a considerable time to run depending on the...
1
by: VM | last post by:
How can I cancel all running processes in my application when I click on the Cancel button? When the Run button's clicked, it creates an instance of a specified class and runs a method that reads...
2
by: InvisibleDuncan | last post by:
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message...
4
by: genojoe | last post by:
I have a combobox control on the form. When the user makes a change, I want to validate a condition before permitting the change. If the condition is not met, I want to return the ComboBox text...
0
by: stand__sure | last post by:
Although I am aware of methods to kill an existing thread that is explicitly created in code, I am wondering if a method exists to do so with a pool thread that would be used when calling...
4
by: Silent Fire | last post by:
Hi there :D I have made my images all transparent with a basic img {filter:mask; height:0; } and then, when i mouseover(oh i mean hover :P ) i want the images to come up inverted img:hover...
7
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a thread that pulls data from the SQL Server. After running a query, if the DataTable has records, I go on to process them. If the DataTable does not have records, I want to exit the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.