[RESOLVED] How to stop my application in a loop.
Hello everyone... I have something to ask again.. I develop a program that will send bulk messages but the problem is that when I load at least 1000 emails then I want to stop the application I cannot stop it. Is there any way to stop this application without closing the form? So that i can save the file on my listview? Here is my code upon send bulk emails.
Code:
Private Sub frmStatus_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Dim i As Integer
Dim holder As String
'Dim itemstring As String
Dim LVITem As New ListViewItem
Try
For i = 0 To ListView1.Items.Count - 1
holder = ListView1.Items(i).SubItems(1).Text
sendHTMLmail()
ListView1.Items(i).SubItems(2).Text = carrier
lblCount.Text = i + 1
lblLvwCount.Text = ListView1.Items.Count
SmoothProgressBar2.Value = (i + 1) * 100 / ListView1.Items.Count
Label1.Text = ((i + 1) * 100 / ListView1.Items.Count).ToString("N", nfi) + "%"
Next
btnLog.Visible = True
btnStop.Enabled = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
One problem I encountered also is that once the mail started to send and the user will click my listview my application will stop sending and I cannot stop the application anymore so if this happen I end up the application by using the stop in a task manager. Anyone can help me to this? Thanks in advance and have a nice day.
Re: How to stop my application in a loop.
Hmm... you may find people reticent to help you with a program for automatically sending out thousands of e-mails .
I assume that you have a copy and paste error in your frmStatus.Shown event as you have an "Else If" statement without an "If" preceding it.
Re: How to stop my application in a loop.
put a counter in your codes and increment it every time you send an email, then when counter >1000 you will stop sending, or do you want to stop by hitting a button?
Re: How to stop my application in a loop.
Quote:
Originally Posted by
keystone_paul
Hmm... you may find people reticent to help you with a program for automatically sending out thousands of e-mails .
I assume that you have a copy and paste error in your frmStatus.Shown event as you have an "Else If" statement without an "If" preceding it.
:) I edited my code now paul. Is it the right place paul to put my code in my frmStatus.shown upon sending? Once I started the mail then it won't stop.:(
Re: How to stop my application in a loop.
Quote:
Originally Posted by
rheimon
put a counter in your codes and increment it every time you send an email, then when counter >1000 you will stop sending, or do you want to stop by hitting a button?
I want to stop by hitting the button.... How can I do that?
Re: How to stop my application in a loop.
Have the stop button set i equal to whatever is necessary to stop the for loop?
Re: How to stop my application in a loop.
Use a BackgroundWorker. Follow the CodeBank link in my signature and you'll find my submission on the subject, which demonstrates how to update the UI and also how to cancel the background operation.