SevenZipSharp: Aborting In ProgressCompression - sevenzipsharp

Using SevenZipSharp wrapper has anyone succeeded in aborting an in-progress compression? I used:
FileCompressionStarted(ByVal sender As Object, ByVal e As SevenZip.FileNameEventArgs)
to see some activity and tried:
e.cancel = true
but nothing happened. Compression continues working until all files are packed. Any ideas?

resolved and explained in other forum, please see link, thanks everyone
http://www.vbforums.com/showthread.php?697661-RESOLVED-SevenZipSharp-aborting-compression&p=4272389#post4272389
PS. Just to have solution here, in case anyone needs
e.cancel isn't treated well in library because (like I expected) when I set e.cancel = true once, the library may not catch this request. I'm not sure this is sevenzipsharp.dll problem or 7z.dll but in code posted, when many clicks hits to my Abort button, finally, library aborted compression !!!
So implementation needs to be:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
abort = True
console.addLine("Abort requested...")
End Sub
Private Sub fFileCompressionStarted(ByVal sender As Object, ByVal e As SevenZip.FileNameEventArgs)
Dim s As String = ""
If abort Then
e.Cancel = True
s = " aborted"
End If
console.addLine("[CompressionStarted event] e.Filename = " + e.FileName + ", e.PercentDone = " + e.PercentDone.ToString + s)
End Sub
Public Sub fCompressionFinished(ByVal sender As Object, ByVal e As System.EventArgs)
console.addLine("[CompressionFinished event]")
abort = False
End Sub
Best regards,
Edouard Gora, YO3HCV

Related

What is wrong with this attempt to get a JSON value?

I'm trying to get the Json value and put it in a label, the syntax seems to be correct, but there sure is something wrong with the code, the value simply doesn't display on the Label. What can it be?
NOTE: I have already added the Newstonsoft JSON reference and the timer is 5 seconds and is activated after the form is loaded.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim json = New IO.StreamReader(DirectCast(DirectCast(Net.WebRequest.Create("https://www.bitstamp.net/api/ticker/"), Net.HttpWebRequest).GetResponse, Net.HttpWebResponse).GetResponseStream)
Dim rq As Newtonsoft.Json.Linq.JToken = Newtonsoft.Json.Linq.JObject.Parse(json.ReadToEnd)
BitCoinPrice = $"{rq.SelectToken("last")}"
Label1.Text = BitCoinPrice
End Sub
I was inattentive but realized that I put the code to activate the Timer1 in the wrong place, instead of putting it when the form loads, it was in when WebBrowser1 loads.
Wrong
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Timer1.Enabled = True 'Wrong Place
End Sub
Correct
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = True 'Correct Place
End Sub
Sorry for the inconvenience and thanks for the help.

BackgroundWorker not Running when it's needed

I am writing a program which lets users upload a large file, compare it to another large file uploaded before and return a list of new entries and discontinued entries.
This requires the program to run a few queries, so it takes a while for the program to complete the task.
Of course, this means that until the program is done with the task, the user cannot do anything else. To prevent that from happening I have included a BackgroundWorker to the project.
The problem is, the BackgroundWorker doesn't start, giving me the same problem.
Can you please help me with this problem? Thanks!
Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim opendialog As New OpenFileDialog
Dim filepath As String = ""
Dim cellvalue(20) As String
opendialog.Title = "Elija el archivo que quiere importar"
opendialog.Filter = "CSV (*.csv)|*.csv"
If opendialog.ShowDialog() = DialogResult.Cancel Then
Exit Sub
End If
filepath = Replace(opendialog.FileName, "\", "\\")
Label1.Visible = True 'This is supposed to appear first, but it doesn't appear until the end of the method.
'Reading CSV file content
Cmd.CommandText = "SELECT COUNT(*) AS cuenta FROM libros WHERE 1"
rs = Cmd.Execute
If rs("cuenta").Value = 0 Then
BackgroundWorker1.RunWorkerAsync()
'MySQL queries, some of which takes a long time due to the large file being processed
Beep()
MsgBox("Archivo exportado con éxito",, "Exito")
BackgroundWorker1.CancelAsync()
Else
BackgroundWorker1.RunWorkerAsync()
'MySQL queries, some of which takes a long time due to the large file being processed
Beep()
MsgBox("Archivo exportado con éxito",, "Exito")
BackgroundWorker1.CancelAsync()
End If
End Sub
Private Sub BackgroundWoker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
' Update the progress bar
Me.ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
If e.Cancelled Then
Label1.Text = "Cancelled"
Else
Label2.Text = "Completed"
End If
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object,
ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork
' Do some time-consuming work on this thread.
System.Threading.Thread.Sleep(5)
End Sub
RunWorkerAsync is, as the name implies, an async method call. This means that the only work done here is to start the DoWork event handler and return immediately. Thus your code now has two paths of execution, the one in the DoWork event handler (that has just started its work and it has probably done nothing) and the code that follows the call to RunWorkerAsync (the code in the ButtonClick).
This last code shows a messagebox and then call CancelAsync, and you could imagine what this call do to your DoWork thread of execution.
So you just need to wait before displaying anything and the Completed event is exactly what you need to use to wait the completition of your DoWork event handler
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
.....
BackgroundWorker1.RunWorkerAsync()
' Remove these lines....
' Beep()
' MsgBox("Archivo exportado con éxito",, "Exito")
' BackgroundWorker1.CancelAsync()
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
If e.Cancelled Then
Label1.Text = "Cancelled"
Else
Label2.Text = "Completed"
' Add the message here....'
Beep()
MsgBox("Archivo exportado con éxito",, "Exito")
' Of course at this point you don't need to cancel anything....'
End If
End Sub
Private Sub BackgroundWoker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
Me.ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object,
ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles BackgroundWorker1.DoWork
' Now suppose that your work here could be divided in 5 methods'
ExecuteMethod1()
backgroundWorker1.ReportProgress(20)
ExecuteMethod2)
backgroundWorker1.ReportProgress(40
ExecuteMethod3
backgroundWorker1.ReportProgress(60)
ExecuteMethod4
backgroundWorker1.ReportProgress(80)
ExecuteMethod5
backgroundWorker1.ReportProgress(100)
End Sub

How to know the path file of image in picturebox?

I have a picturebox where I load a image at runtime using a OpenFileDialog, then I want to save the path/filename into a database. What I don't know is how to get the path/filename of the image?
I tried something like
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
openFD.ShowDialog()
If openFD.FileName > "" Then
PictureBox1.ImageLocation = openFD.FileName
PictureBox1.Imagelocation = label1.text
End If
End Sub
label1.text = PictureBox1.ImageLocation
or you can try to msgbox(PictureBox1.ImageLocation)

only number validation code in vb.net

only number validation code in vb.net i have used this code but when i want to update it the code doesn't allow me to change or delete the number it doesn't even allows backspace button to work what changes can i make ??? to update the mobile no i m using sql server database
Private Sub txtcustcontact_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcustcontact.KeyPress
If Not IsNumeric(e.KeyChar) Then
Tip.Show("Enter Numeric Value Only ", sender)
e.KeyChar = Nothing
End If
End Sub
You can try as below:
Private Sub txtcustcontact_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcustcontact.KeyPress
If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
MessageBox.Show("Please enter Numeric values only")
e.Handled = True
End If
End Sub

backgroundworker retrieve data from database. timeout expired

This is the first time I use background worker. I want to retrieve data around 20.000 rows, save it on dataadapter and showing in on a datagridview
it seems running but then message Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding comes up.
What I have done is put : Connect Timeout=90000 on the connection string and da.SelectCommand.CommandTimeout = 2000000, which doesn't seems to have a better end result by make adding few extra zeroes. :(
Here is what I have done. What should I do to make it works. thank you
Dim da As MySqlDataAdapter
Dim resultDataTable As DataTable
Dim queryString As String
Private Sub BTNrefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNrefresh.Click
queryString =" LONG QUERY "
bw.RunWorkerAsync()
End Sub
Private Sub bw_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bw.DoWork
MethodGlobal.mySqlCon.Open()
da = New MySqlDataAdapter(queryString, MethodGlobal.mySqlCon)
myDataTable = New DataTable
da.Fill(myDataTable)
da.SelectCommand.CommandTimeout = 2000000
Me.DGVtest.DataSource = resultDataTable
End Sub
Private Sub backgroundworker_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MethodGlobal.NewMysqlConnection("connection")
End Sub