473,320 Members | 1,699 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,320 software developers and data experts.

should i use thread.abort to stop code execution?

I'm attempting to load a form, query a database, and update a progress bar
on the same form. I want the form to load and activate/enable the form's
cancel button while the code continues to execute and the progress bar
updates. The user will be able to press the cancel button to stop
execution. Everything works fine, but I've noticed that when I call
thread.Abort, an exception is thrown: "Thread was being aborted."

Is there a better way to accomplish this task? (see code below)

Thanks!

Matt

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Show()

thread = New System.Threading.Thread(AddressOf
Me.UpdateCheckListStatus)

thread.Start()
End Sub

Private Function CreateMessage(ByVal pastDueUsers As UserCollection) As
String
'do something here
End Function

Private Sub UpdateCheckListStatus()
try
Dim u As New UserCollection
Dim message As String
Dim email As New anEmail.cStore
Dim recipients(0) As String
Dim pastDueUnderwriters As New UserCollection
Dim pastDueAssociates As New UserCollection
Dim pastDueOtherUsers As New UserCollection

ProgressBar1.Step = 1

ProgressBar1.Minimum = 0

ProgressBar1.Maximum = 7

pastdueItem.UpdateCheckListStatus(ConfigurationSet tings.AppSettings("PastDueDays"))

ProgressBar1.PerformStep()

u =
user.GetAllUsers(ConfigurationSettings.AppSettings ("PastDueDays"))

ProgressBar1.PerformStep()

For Each user As User In u
If user.hasPastDueItems Then
If user.Title = Title.ASSOCIATE Then
pastDueAssociates.Add(user)
ElseIf user.Title = Title.UNDERWRITER Then
pastDueUnderwriters.Add(user)
Else
pastDueOtherUsers.Add(user)
End If
For Each pastdueItem As PastDueItem In user.PastDueItems
message += String.Format("{0} [{1}] {2}",
pastdueItem.PolicyNumber, pastdueItem.BusinessType,
pastdueItem.ReceivedDate.ToString("d")) & vbCrLf
Next

recipients(0) = String.Format("{0*@anpac.com", user.ID)

'email.StoreMessage(recipients,
"Up*******************@anpac.com", "Past Due Items", message)
End If
Next

ProgressBar1.PerformStep()

pastDueAssociates.Sort(UserSortType.Division)
pastDueUnderwriters.Sort(UserSortType.Division)
pastDueOtherUsers.Sort(UserSortType.Division)

ProgressBar1.PerformStep()

message = CreateMessage(pastDueAssociates)

If Not message = String.Empty Then
For Each user As User In u
If user.Title = Title.SUPERVISOR Then
'email.StoreMessage(recipients,
"Up*******************@anpac.com", "Past Due Items", message)
End If
Next
End If

ProgressBar1.PerformStep()

message = String.Empty

message = CreateMessage(pastDueUnderwriters)

If Not message = String.Empty Then
For Each user As User In u
If user.Title = Title.SUPERVISOR Then
'email.StoreMessage(recipients,
"Up*******************@anpac.com", "Past Due Items", message)
End If
Next
End If

ProgressBar1.PerformStep()

message = String.Empty

message = CreateMessage(pastDueOtherUsers)

If Not message = String.Empty Then
'email.StoreMessage(recipients,
"Up*******************@anpac.com", "Past Due Items", message)
End If

ProgressBar1.PerformStep()
catch ex as exception
msgbox(ex.message)
end try
End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancel.Click
thread.Abort()
End Sub
Mar 6 '06 #1
0 1164

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

Similar topics

14
by: Daisy | last post by:
From this page: http://www.c-sharpcorner.com/2/mt_beginner1.asp Thread class's Abort method is called to kill a thread permanently. Make sure you call IsAlive before Abort. if (...
7
by: Morris | last post by:
I want to abort a running thread, so I call MyThread.abort() function. My problem is this thread runs "almost" like a while(true) loop and I don't want the Abort() function interrupts the thread at...
18
by: Urs Vogel | last post by:
Hi I wrote an application server (a remoting sinlgeton), where processes must be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and only after a Thread.Abort(), this...
1
by: Robin Tucker | last post by:
Hi there, I have a "worker thread", which can perform one of many tasks, including fetching and sending data blobs to a database, load files etc. Now, a progress dialog is displayed while the...
10
by: Brett | last post by:
I have a second thread in which I call t.abort() from the parent thread. I see "t"s state as AbortRequested. It stays this way for some time. Under which conditions will a thread remain this way? ...
6
by: Joe HM | last post by:
Hello - I have a function that calls Thread.Abort() to stop a thread in a _Closed() Method of a GUI. The thread contains a blocking call on a TCP socket and that is the easiest way to stop...
10
by: Jon Slaughter | last post by:
Since a thread doesn't have a Stop feature and I'm not supose to use abort, I'm wondering how I stop a thread? My problem is that I simply want to excute a function in the background and...
0
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a...
6
by: mehdi | last post by:
Hi folks, You know, the Thread class has got a method named Abort which according to the msdn: "Raises a ThreadAbortException in the thread on which it is invoked, to begin the process of...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: 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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.