How to show MsgBox after finishing unzip process - vb.net

I have this code:
Private Sub KickoffExtract()
actionStatus.Text = "Se instaleaza actualizarea.. va rugam asteptati."
lblProgress.Text = "Se extrage..."
Dim args(2) As String
args(0) = GetSettingItem("./updUrl.info", "UPDATE_FILENAME")
args(1) = extractPath
_backgroundWorker1 = New System.ComponentModel.BackgroundWorker()
_backgroundWorker1.WorkerSupportsCancellation = False
_backgroundWorker1.WorkerReportsProgress = False
AddHandler Me._backgroundWorker1.DoWork, New DoWorkEventHandler(AddressOf Me.UnzipFile)
_backgroundWorker1.RunWorkerAsync(args)
End Sub
Private Sub UnzipFile(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim extractCancelled As Boolean = False
Dim args() As String = e.Argument
Dim zipToRead As String = args(0)
Dim extractDir As String = args(1)
Try
Using zip As ZipFile = ZipFile.Read(zipToRead)
totalEntriesToProcess = zip.Entries.Count
SetProgressBarMax(zip.Entries.Count)
AddHandler zip.ExtractProgress, New EventHandler(Of ExtractProgressEventArgs)(AddressOf Me.zip_ExtractProgress)
zip.ExtractAll(extractDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
End Using
Catch ex1 As Exception
MessageBox.Show(String.Format("Actualizatorul a intampinat o problema in extragerea pachetului. {0}", ex1.Message), "Error Extracting", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End Try
End Sub
Private Sub SetProgressBarMax(ByVal n As Integer)
If ProgBar.InvokeRequired Then
ProgBar.Invoke(New Action(Of Integer)(AddressOf SetProgressBarMax), New Object() {n})
Else
ProgBar.Value = 0
ProgBar.Maximum = n
ProgBar.Step = 1
End If
End Sub
Private Sub zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
If _operationCanceled Then
e.Cancel = True
Return
End If
If (e.EventType = Ionic.Zip.ZipProgressEventType.Extracting_AfterExtractEntry) Then
StepEntryProgress(e)
ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractAll) Then
End If
End Sub
Private Sub StepEntryProgress(ByVal e As ExtractProgressEventArgs)
If ProgBar.InvokeRequired Then
ProgBar.Invoke(New ZipProgress(AddressOf StepEntryProgress), New Object() {e})
Else
ProgBar.PerformStep()
System.Threading.Thread.Sleep(100)
nFilesCompleted = nFilesCompleted + 1
lblProgress.Text = String.Format("{0} din {1} fisiere...({2})", nFilesCompleted, totalEntriesToProcess, e.CurrentEntry.FileName)
Me.Update()
End If
End Sub
and this code on a button:
If Not File.Exists("./" + GetSettingItem("./updUrl.info", "UPDATE_FILENAME")) Then
MessageBox.Show("Actualizarea nu s-a descarcat corespunzator.", "Nu se poate extrage", MessageBoxButtons.OK)
End If
If Not String.IsNullOrEmpty("./" + GetSettingItem("./updUrl.info", "UPDATE_FILENAME")) And
Not String.IsNullOrEmpty(extractPath) Then
If Not Directory.Exists(extractPath) Then
Directory.CreateDirectory(extractPath)
End If
nFilesCompleted = 0
_operationCanceled = False
btnUnzip.Enabled = False
KickoffExtract()
End If
How can I show a message after completing the UnZip process? I tried
If ProgBar.Maximum Then
MsgBox("finish")
End If
but it doesn't work. I'm using dotnetzip 1.9, and the most of the code is from UnZip example.

If you check the documentation of BackgroundWorker you will notice that there are two events that can be linked to an event handler in your code.
One of them is the RunWorkerCompleted and in the MSDN page they say
Occurs when the background operation has completed, has been canceled,
or has raised an exception.
So, it is just a matter to write an event handler and bind the event.
AddHandler Me._backgroundWorker1.RunWorkerCompleted, New RunWorkerCompletedEventHandler(AddressOf Me.UnzipComplete)
and then
Private Sub UnzipComplete(ByVal sender As System.Object, _
ByVal e As RunWorkerCompletedEventArgs)
If e.Cancelled = True Then
MessageBox.Show("Canceled!")
ElseIf e.Error IsNot Nothing Then
MessageBox.Show("Error: " & e.Error.Message)
Else
MessageBox.Show("Unzip Completed!")
End If
End Sub

Related

How To Fetch Webpage Source simultaneously from thousands of URLs

I am attempting to load thousands of URLs into a list, then simultaneously download the webpage source of all of those URLs. I thought I had a clear understanding of how to accomplish this but it seems that the process goes 1 by 1 (which is painstakingly slow).
Is there a way to make this launch all of these URLs at once, or perhaps more than 1 at a time?
Public Partial Class MainForm
Dim ImportList As New ListBox
Dim URLList As String
Dim X1 As Integer
Dim CurIndex As Integer
Public Sub New()
Me.InitializeComponent()
End Sub
Sub MainFormLoad(sender As Object, e As EventArgs)
Try
Dim lines() As String = IO.File.ReadAllLines("C:\URLFile.txt")
ImportList.Items.AddRange(lines)
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
label1.Text = "File Loaded"
X1 = ImportList.Items.Count
timer1.Enabled = True
If Not backgroundWorker1.IsBusy Then
backgroundWorker1.RunWorkerAsync()
End If
End Try
End Sub
Sub BackgroundWorker1DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)
URLList = ""
For Each item As String In ImportList.Items
CheckName(item)
CurIndex = CurIndex + 1
Next
End Sub
Sub BW1_Completed()
timer1.Enabled = False
label1.Text = "Done"
End Sub
Sub CheckName(ByVal CurUrl As String)
Dim RawText As String
Try
RawText = New System.Net.WebClient().DownloadString(CurUrl)
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
If RawText.Contains("404") Then
If URLList = "" Then
URLList = CurUrl
Else
URLList = URLList & vbCrLf & CurUrl
End If
End If
End Try
End Sub
Sub Timer1Tick(sender As Object, e As EventArgs)
label1.Text = CurIndex.ToString & " of " & X1.ToString
If Not URLList = "" Then
textBox1.Text = URLList
End If
End Sub
Sub Button1Click(sender As Object, e As EventArgs)
Clipboard.Clear
Clipboard.SetText(URLList)
End Sub
End Class

SSL/TLS connection not working in webclient after being in background

So if I use my program normally no error occurs. But if it is in background for longer time and I use the webclient to visit a web address it immidiately throws could not create a SSL/TLS secure channel error but if I try again the error dissapears. I already set the TLS to 1.2 and expect100continue to false.
Imports System.Net
Imports System.Text.RegularExpressions
Public Class CinemaLinker
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MaximizeBox = False
If Not HaveInternetConnection() Then
MessageBox.Show("Warning: no internet connection!")
End If
ServicePointManager.Expect100Continue = False
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
End Sub
Public Property TextFromBox As String
Public Property StatusLink As String
Private Client As New WebClient
Private GoogleSearch = "****"
Private BingSearch = "*****"
Private AskSearch = "*****"
Private Sub Search() Handles Button1.Click
Cursor.Current = Cursors.WaitCursor
TextFromBox = RichTextBox1.Text
If Button3.Enabled And Button4.Enabled Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Please choose a category!")
Exit Sub
End If
If TextFromBox.Contains("Type movie or tv series name here") Or String.IsNullOrEmpty(TextFromBox) Or String.IsNullOrWhiteSpace(TextFromBox) Then
Cursor.Current = Cursors.[Default]
If Not Button3.Enabled Then
MessageBox.Show("Please type the name of the movie!")
Exit Sub
End If
If Not Button4.Enabled Then
If Not (String.IsNullOrEmpty(RichTextBox3.Text) Or String.IsNullOrWhiteSpace(RichTextBox3.Text) Or RichTextBox3.Text.Contains("E")) Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Please type the name of the tv series! Episode number missing!")
Exit Sub
End If
If String.IsNullOrEmpty(RichTextBox2.Text) Or String.IsNullOrWhiteSpace(RichTextBox2.Text) Or RichTextBox2.Text.Contains("S") Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Please type the name of the tv series! Season and episode numbers missing!")
Exit Sub
End If
Cursor.Current = Cursors.[Default]
MessageBox.Show("Please type the name of the tv series!")
Exit Sub
End If
End If
If Not Button4.Enabled Then
If String.IsNullOrEmpty(RichTextBox3.Text) Or String.IsNullOrWhiteSpace(RichTextBox3.Text) Or RichTextBox3.Text.Contains("E") Then
If String.IsNullOrEmpty(RichTextBox2.Text) Or String.IsNullOrWhiteSpace(RichTextBox2.Text) Or RichTextBox2.Text.Contains("S") Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Season and episode numbers missing!")
Exit Sub
End If
Cursor.Current = Cursors.[Default]
MessageBox.Show("Episode number missing!")
Exit Sub
ElseIf String.IsNullOrEmpty(RichTextBox2.Text) Or String.IsNullOrWhiteSpace(RichTextBox2.Text) Or RichTextBox2.Text.Contains("S") Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Season number missing!")
Exit Sub
End If
End If
If Not HaveInternetConnection() Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("No internet connection!")
Exit Sub
End If
Dim ImdbURL As String = getIMDbUrl(TextFromBox)
If Not ImdbURL.Contains("******") And Not Button3.Enabled Then
ImdbURL = getIMDbUrl(TextFromBox) + " movie"
If Not ImdbURL.Contains("***") And Not Button3.Enabled Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Movie not found! Please add the year in the name!")
Exit Sub
End If
End If
If Not ImdbURL.Contains("***") And Not Button4.Enabled Then
ImdbURL = getIMDbUrl(TextFromBox) + " TV series"
If Not ImdbURL.Contains("****") And Not Button4.Enabled Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("TV series not found! Please add the year in the name!")
Exit Sub
End If
End If
Dim LinkFinal As String = (GetLink(ImdbURL))
If String.IsNullOrEmpty(LinkFinal) Or String.IsNullOrWhiteSpace(LinkFinal) Then
Cursor.Current = Cursors.[Default]
Exit Sub
End If
Clipboard.SetText(LinkFinal)
MessageBox.Show("Link in clipboard. Paste it into desired browser!")
TextFromBox = String.Empty
StatusLink = "0"
Cursor.Current = Cursors.[Default]
End Sub
Public Function HaveInternetConnection() As Boolean
Dim result As Boolean
Try
result = My.Computer.Network.Ping("www.google.com")
Catch ex As Exception
result = False
End Try
Return result
End Function
Private Function GetIP() As String
Return Client.DownloadString("https://api.ipify.org").ToString()
End Function
Private Function matchAll(ByVal regex As String, ByVal html As String, ByVal Optional i As Integer = 1) As ArrayList
Dim list As ArrayList = New ArrayList()
For Each m As Match In New Regex(regex, RegexOptions.Multiline).Matches(html)
list.Add(m.Groups(i).Value.Trim())
Next
Return list
End Function
Private Function getIMDbUrl(MovieName As String, Optional searchEngine As String = "google") As String
Dim address As String = GoogleSearch + MovieName
If searchEngine.ToLower().Equals("bing") Then
address = BingSearch + MovieName
End If
If searchEngine.ToLower().Equals("ask") Then
address = AskSearch + MovieName
End If
Dim html As String = Client.DownloadString(address)
Dim arrayList As ArrayList = matchAll("<a href=""(*****\d{7}/)"".*?>.*?</a>", html, 1)
If arrayList.Count > 0 Then
Return CStr(arrayList(0))
ElseIf searchEngine.ToLower().Equals("google") Then
Return getIMDbUrl(MovieName, "bing")
ElseIf searchEngine.ToLower().Equals("bing") Then
Return getIMDbUrl(MovieName, "ask")
Else
Return String.Empty
End If
End Function
Private Function GetLink(ImdbURL As String) As Object
Dim ID = ImdbURL.Replace("*****/", "")
ID = ID.Replace("/", "")
Dim result As Object
If StatusLink = "1" Then
Cursor.Current = Cursors.[Default]
Exit Function
ElseIf Not Button4.Enabled Then
Dim SeasonNumber As String = "&s=" + RichTextBox2.Text
Dim EpisodeNumber As String = "&e=" + RichTextBox3.Text
Dim TVSeasonNumber As String = "&tv=1" + SeasonNumber
If Not Client.DownloadString("*****/" & ID).Contains(">Episode Guide<") Then
ImdbURL = getIMDbUrl(TextFromBox + " TV series")
StatusLink = "1"
If String.IsNullOrEmpty(ImdbURL) Or String.IsNullOrWhiteSpace(ImdbURL) Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("TV series not found! Please add the year in the name or check category!")
result = String.Empty
Exit Function
Else
ID = ImdbURL.Replace("*****", "")
ID = ID.Replace("/", "")
result = (GetLink(ImdbURL))
If String.IsNullOrEmpty(result) Or String.IsNullOrWhiteSpace(result) Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("TV series not found! Please add the year in the name or check category!")
result = String.Empty
Exit Function
Else
Return result.ToString()
result = String.Empty
Exit Function
End If
End If
Else
Dim address As String = "******" & ID & TVSeasonNumber & "&ip=" & GetIP()
Dim token As String = Client.DownloadString(address)
result = "*****" & ID & TVSeasonNumber & EpisodeNumber & "&ticket=" & token
Return result.ToString
Exit Function
End If
ElseIf Not Button3.Enabled Then
If Client.DownloadString("****" & ID).Contains(">Episode Guide<") Then
ImdbURL = getIMDbUrl(TextFromBox + " movie",)
StatusLink = "1"
If String.IsNullOrEmpty(ImdbURL) Or String.IsNullOrWhiteSpace(ImdbURL) Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Movie not found! Please add the year in the name or check category!")
result = String.Empty
Exit Function
Else
ID = ImdbURL.Replace("****", "")
ID = ID.Replace("/", "")
result = (GetLink(ImdbURL))
If String.IsNullOrEmpty(result) Or String.IsNullOrWhiteSpace(result) Then
Cursor.Current = Cursors.[Default]
MessageBox.Show("Movie not found! Please add the year in the name or check category!")
result = String.Empty
Exit Function
Else
Return result.ToString()
result = String.Empty
Exit Function
End If
End If
Else
Dim address2 As String = "****" & ID & "&ip=" & GetIP()
Dim token2 As String = Client.DownloadString(address2)
result = "****" & ID & "&ticket=" & token2
Return result.ToString
result = String.Empty
Exit Function
End If
End If
#Disable Warning BC42105 ' Function doesn't return a value on all code paths
End Function
Private Sub RichTextBox1_MouseClick(sender As Object, e As EventArgs) Handles RichTextBox1.GotFocus
If RichTextBox1.Text.Contains("Type movie or tv series name here") Then RichTextBox1.Text = String.Empty
End Sub
Private Sub RichTextBox2_MouseClick(sender As Object, e As EventArgs) Handles RichTextBox2.GotFocus
If RichTextBox2.Text.Contains("S") Then RichTextBox2.Text = String.Empty
End Sub
Private Sub RichTextBox3_MouseClick(sender As Object, e As EventArgs) Handles RichTextBox3.GotFocus
If RichTextBox3.Text.Contains("E") Then RichTextBox3.Text = String.Empty
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Button3.Enabled = False
Button4.Enabled = True
RichTextBox1.Enabled = True
RichTextBox2.Enabled = False
RichTextBox3.Enabled = False
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Button4.Enabled = False
Button3.Enabled = True
RichTextBox1.Enabled = True
RichTextBox2.Enabled = True
RichTextBox3.Enabled = True
End Sub
Private Sub RichTextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox2.KeyPress
If Char.IsLetter(e.KeyChar) Then
e.Handled = True
End If
If CType(e, KeyPressEventArgs).KeyChar = vbCr Then
Search()
End If
End Sub
Private Sub RichTextBox3_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox3.KeyPress
If Char.IsLetter(e.KeyChar) Then
e.Handled = True
End If
If CType(e, KeyPressEventArgs).KeyChar = vbCr Then
Search()
End If
End Sub
Private Sub RichTextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles RichTextBox1.KeyPress
If CType(e, KeyPressEventArgs).KeyChar = vbCr Then
Search()
End If
If Char.IsUpper(e.KeyChar) Then e.KeyChar = Char.ToLower(e.KeyChar)
End Sub
Private Sub RichTextBox1_Lostfocus(sender As Object, e As EventArgs) Handles RichTextBox1.LostFocus
If String.IsNullOrEmpty(RichTextBox1.Text) Or String.IsNullOrWhiteSpace(RichTextBox1.Text) Then
RichTextBox1.Text = "Type movie or tv series name here..."
End If
End Sub
Private Sub RichTextBox2_Lostfocus(sender As Object, e As EventArgs) Handles RichTextBox2.LostFocus
If String.IsNullOrEmpty(RichTextBox2.Text) Or String.IsNullOrWhiteSpace(RichTextBox2.Text) Then
RichTextBox2.Text = "S:"
End If
End Sub
Private Sub RichTextBox3_Lostfocus(sender As Object, e As EventArgs) Handles RichTextBox3.LostFocus
If String.IsNullOrEmpty(RichTextBox3.Text) Or String.IsNullOrWhiteSpace(RichTextBox3.Text) Then
RichTextBox3.Text = "E:"
End If
End Sub
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged
StatusLink = "0"
End Sub
Private Sub RichTextBox2_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox2.TextChanged
StatusLink = "0"
End Sub
Private Sub RichTextBox3_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox3.TextChanged
StatusLink = "0"
End Sub
End Class
all of the ***** are https website addresses.
Tried switching the Net version to 4.7. Did not help. It is also legal in my country to stream (interior minister dropped a bomb on the DMCA here lol) and this is streaming only. The code is not operational so i had not given you anything dangerous if it is illegal in yours.

BackgroundWorker's ProgressChanged not updating UI until end of work loop

I am coding a WPF application that will grab email's off of an IMAP account, and then export them into a user-selected folder.
I use a BackgroundWorker to download the emails. However, my UI isn't being updated until the loop is over.
Any tips would be appreciated.
Class MainWindow
Public MailRepo As MailRepository
Private bw_Connect As New BackgroundWorker
Private bw_Save As New BackgroundWorker
Public Sub New()
InitializeComponent()
bw_Connect.WorkerReportsProgress = True
bw_Connect.WorkerSupportsCancellation = True
AddHandler bw_Connect.DoWork, AddressOf bw_Connect_DoWork
bw_Save.WorkerReportsProgress = True
bw_Save.WorkerSupportsCancellation = True
AddHandler bw_Save.DoWork, AddressOf bw_Save_DoWork
AddHandler bw_Save.ProgressChanged, AddressOf bw_Save_ProgressChanged
End Sub
Private Sub bw_Save_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
If bw_Connect.CancellationPending = True Then
e.Cancel = True
Else
SaveEmails()
End If
End Sub
Private Sub SaveEmails()
Dim allMails As IEnumerable(Of Message)
'Get All Emails in Mailbox
Try
Dim mailBox As String
Dispatcher.Invoke(DirectCast(Sub()
mailBox = comboBoxEmailFolders.SelectedValue
End Sub, Action))
allMails = MailRepo.GetAllMails(mailBox)
Catch i4e As Imap4Exception
MsgBox("Error: Folder not found" & vbCrLf & i4e.Message)
Return
End Try
Dim msg As Message
Dim msgInt As Integer = 1
'Save each message
For Each msg In allMails
bw_Save.ReportProgress(100 / allMails.Count * msgInt, Nothing)
SaveMessage(msg)
msgInt += 1
Next
End Sub
Private Sub bw_Save_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
Dim percentDone As String = e.ProgressPercentage.ToString() & "%"
updateStatus("Saving Emails " & percentDone & " done.")
progressBarStatus.Value = e.ProgressPercentage
End Sub

Thread-Safe Hide form

I'm trying to make a "loading..." form in a DLL with a simple animation using a BackgroundWorker (netMessageInWait).
I have a Show function that load the form, set all texts and run the BackgroundWorker
Public Sub Show(ByVal WorkingArea As Rectangle, ByVal Title As String, ByVal Message As String)
With wait
If (wait.InvokeRequired) Then
wait.Invoke(Sub()
With .lblTitle
.Text = Title
End With
With .lblMessage
.Text = Message
End With
End Sub)
Else
With .lblTitle
.Text = Title
End With
With .lblMessage
.Text = Message
End With
End If
End With
If (Not backWorker.IsBusy) Then
Dim args As New ShowArgumentType
args.WorkingArea = WorkingArea
args.Title = Title
args.Message = Message
backWorker.WorkerSupportsCancellation = True
backWorker.RunWorkerAsync(args)
End If
End Sub
And the Clear function that stop the BackgroundWorker
Public Sub ClearMessage()
Try
CancelWork = True
backWorker.CancelAsync()
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
The BackgroundWorker_DoWork() that show fisically the form and wait for the ClearMessage
Private Sub backWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles backWorker.DoWork
Dim args As ShowArgumentType = DirectCast(e.Argument, ShowArgumentType)
wait.Show()
While True
Application.DoEvents()
If (CancelWork Or backWorker.CancellationPending) Then
Exit While
End If
End While
End Sub
And then the BackgroundWorker_RunWorkerCompleted() that Hide the form
Private Sub backWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles backWorker.RunWorkerCompleted
CancelWork = False
Call ShowHideForm_ThreadSafe(wait, False) ' HERE THE PROBLEM
Debug.Print("Work completed")
End Sub
Ok...wath I'm not understanding is why I try to hide the form with the function below the program freez at the BeginInvoke...
Private Sub ShowHideForm_ThreadSafe(ByVal pform As Form, _
ByVal pshow As Boolean)
If pform.InvokeRequired Then
Dim MyDelegate As New ShowHideForm_Delegate(AddressOf ShowHideForm_ThreadSafe)
pform.BeginInvoke(MyDelegate, New Object() {[pform], [pshow]})
Else
If (pshow) Then
pform.Show()
Else
pform.Hide()
End If
End If
End Sub
Please help me! How can I solve this issue?
Thanks!

Visual Basic: Make 1 button do 2 operations

So I need a button to complete two operations but in two steps. Here is the first buttons code:
First button (button6)
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
p = Process.GetProcessesByName("SbieSvc")
If p.Count > 0 Then
Environment.Exit(0)
Else
End If
Dim antiProcess() As String = {"SbieSvc", "Sandboxiecrypto", "sbiectrl"}
For intI As Integer = 0 To antiProcess.GetUpperBound(0)
For Each x As Process In Process.GetProcessesByName(antiProcess(intI))
x.Kill()
Next
Next
''Sets the Channel''
If TextBox6.Text = "" Then
MsgBox("Please enter a Channelname!", MsgBoxStyle.Information, ("Error"))
GoTo Bottom
End If
Me.Data = Me.TextBox6.Text
Me.Method_1(String.Format("Channel set ({0})", Data))
If (Me.thread0 Is Nothing) Then
Me.thread0 = New Thread(New ThreadStart(AddressOf Method2)) With
{
.IsBackground = True
}
Me.thread0.Start()
End If
''Part Of Grab Urls Method''
Button6.Enabled = False
For i As Integer = 0 To TextBox5.Text Step 1
Dim t1 As New Thread(New ParameterizedThreadStart(Sub() GetUrls(TextBox6.Text)))
t1.Start()
Next
GC.SuppressFinalize(Me)
End Sub
Second button (button1)
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
''start live viewers''
Button1.Enabled = False
For Each itemss In Urls.Items
Dim t1 As New Threading.Thread(Sub() LivePeepz(itemss))
t1.Start()
Next
End Sub
How would I make this code so that button6 will complete it's normal commands, then once done it begins button1's operation. I thought about doing this;
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
p = Process.GetProcessesByName("SbieSvc")
If p.Count > 0 Then
Environment.Exit(0)
Else
End If
Dim antiProcess() As String = {"SbieSvc", "Sandboxiecrypto", "sbiectrl"}
For intI As Integer = 0 To antiProcess.GetUpperBound(0)
For Each x As Process In Process.GetProcessesByName(antiProcess(intI))
x.Kill()
Next
Next
''Sets the Channel''
If TextBox6.Text = "" Then
MsgBox("Please enter a Channelname!", MsgBoxStyle.Information, ("Error"))
GoTo Bottom
End If
Me.Data = Me.TextBox6.Text
Me.Method_1(String.Format("Channel set ({0})", Data))
If (Me.thread0 Is Nothing) Then
Me.thread0 = New Thread(New ThreadStart(AddressOf Method2)) With
{
.IsBackground = True
}
Me.thread0.Start()
End If
''Part Of Grab Urls Method''
Button6.Enabled = False
For i As Integer = 0 To TextBox5.Text Step 1
Dim t1 As New Thread(New ParameterizedThreadStart(Sub() GetUrls(TextBox6.Text)))
t1.Start()
Next
GC.SuppressFinalize(Me)
''start live viewers''
Button1.Enabled = False
For Each itemss In Urls.Items
Dim t1 As New Threading.Thread(Sub() LivePeepz(itemss))
t1.Start()
End Sub
But this doesn't work...Any ideas? Thanks. VB2012
Put your code in seperate functions e.g. Function1 would contain the code you intended for first button click. Function2 would have the code intended for second button click.
Then you have one button with an onClick event code that is
Private Sub Button1_Click(byVal sender as Object, byVal e as EventArgs) Handles Button1.Click
Function1()
Function2()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
FirstOperation()
SecondOperation()
End Sub
Private Sub FirstOperation()
'Button 6 Code
End Sub
Private Sub SecondOperation()
'Button 1 Code
End Sub