473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cancelling previous thread

2 New Member
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 1598
Plater
7,872 Recognized Expert Expert
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
machado
2 New Member
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
1872
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. One of the main problems at this point lies in cancelling the event. I have found that the TAB fires the onkeypress in NN, but not in IE. I can...
16
1358
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. That would enable the simple test: var ref = new someObject(); if( ref ) { // Object created successfully }
1
2001
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 criteria that is entered. This query is run on a seperate thread as I wish to return control to the application while this query runs. The user can...
1
7338
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 each line of a file, processes it , and writes it. With the Cancel button, I'd like to cancel this method. Is this possible? Thanks.
2
1959
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 box that warns that their changes will be lost, and asks them to confirm whether to continue. Sounds simple Unfortunately, the ListView's...
4
6997
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 back to its previous value. He is what I tried. (1) Validating event does not work because user is not exiting the control. (2) My condition...
0
879
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 BeginInvoke on a delegate? I suspect that there isn't, but have been unable to confirm this suspicion. Thanks.
4
1479
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 {filter:invert(); height:0; }
7
1651
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 thread. How do I exit the thread? I have tried: /*****************************/ if (table.Rows.Count == 0) { e.Cancel = true; // DoWorkEvenArgs e
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.