Hi,
Im running a timer to Unzip a zip file using a 'ICSharpCode.Sh arpZipLib.dll'.
It works well when I block the main thread indefinitely by 'thread.sleep(-1)'.
But gets an ThreadAbort Exception if i run the timer without thread blocking.
How can i avoid this error?Im not using thread.abort anywhere in my
code.My code to unzip file is taking only 6 sec to complete.
Below im showing the code.
[code=vbnet]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
fnInitiateZipTi mer()
Thread.Sleep(-1)
End Sub
Private Sub objTimer_Elapse d(ByVal sender As Object, ByVal e As System.Timers.E lapsedEventArgs ) Handles objTimer.Elapse d
ExtractArchive_ Global("F:\Proj ects\ZipExtract \Reviews")
End Sub
Sub ExtractArchive_ Global(ByVal strPath As String)
Dim strException As String
Dim sourceDir As String
Dim destDir As String
Dim RenameDir As String
Dim StrFileName As String
Dim StrDir As String
Dim zipFilename As String
Dim ExtractDir As String
If Directory.Exist s(strPath) = False Then
Directory.Creat eDirectory(strP ath)
End If
Try
sourceDir = strPath & "\pwr"
RenameDir = strPath & "\pwr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
destDir = strPath & "\Archive\p wr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
If Directory.Exist s(sourceDir) Then
System.IO.Direc tory.Move(sourc eDir, RenameDir)
If Directory.Exist s(destDir) Then
System.IO.Direc tory.Delete(des tDir, True)
End If
System.IO.Direc tory.Move(Renam eDir, destDir)
End If
zipFilename = strPath & "\pwr.zip"
ExtractDir = strPath
Dim Redo As Integer = 1
Dim MyZipInputStrea m As ZipInputStream
Dim MyFileStream As FileStream
MyZipInputStrea m = New ZipInputStream( New FileStream(zipF ilename, _
FileMode.Open, FileAccess.Read ))
Dim MyZipEntry As ZipEntry = MyZipInputStrea m.GetNextEntry
System.IO.Direc tory.CreateDire ctory(ExtractDi r)
While Not MyZipEntry Is Nothing
If (MyZipEntry.IsD irectory) Then
Try
System.IO.Direc tory.CreateDire ctory(ExtractDi r & "\" & MyZipEntry.Name )
Catch ex As Exception
End Try
Else
Dim _strPath As String
Try
If Not System.IO.Direc tory.Exists(Ext ractDir & "\" & _
System.IO.Path. GetDirectoryNam e(MyZipEntry.Na me)) Then
_strPath = System.IO.Path. GetDirectoryNam e(MyZipEntry.Na me)
System.IO.Direc tory.CreateDire ctory(ExtractDi r & "\" & _strPath)
End If
Catch ex As ThreadAbortExce ption
Thread.ResetAbo rt()
End Try
Try
MyFileStream = New System.IO.FileS tream(ExtractDi r & "\" & _
MyZipEntry.Name , FileMode.OpenOr Create, FileAccess.Writ e)
Dim count As Integer
Dim buffer(50000) As Byte
count = MyZipInputStrea m.Read(buffer, 0, 50000)
While count > 0
MyFileStream.Wr ite(buffer, 0, count)
count = MyZipInputStrea m.Read(buffer, 0, 50000)
End While
buffer = Nothing
MyFileStream.Cl ose()
Catch ex As Exception
End Try
End If
MyZipEntry = MyZipInputStrea m.GetNextEntry
End While
If Not (MyZipInputStre am Is Nothing) Then
MyZipInputStrea m.Close()
End If
If Not (MyFileStream Is Nothing) Then
MyFileStream.Cl ose()
End If
Catch ex As ThreadAbortExce ption
Thread.ResetAbo rt()
End Try
End Sub[/code]
Im running a timer to Unzip a zip file using a 'ICSharpCode.Sh arpZipLib.dll'.
It works well when I block the main thread indefinitely by 'thread.sleep(-1)'.
But gets an ThreadAbort Exception if i run the timer without thread blocking.
How can i avoid this error?Im not using thread.abort anywhere in my
code.My code to unzip file is taking only 6 sec to complete.
Below im showing the code.
[code=vbnet]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
fnInitiateZipTi mer()
Thread.Sleep(-1)
End Sub
Private Sub objTimer_Elapse d(ByVal sender As Object, ByVal e As System.Timers.E lapsedEventArgs ) Handles objTimer.Elapse d
ExtractArchive_ Global("F:\Proj ects\ZipExtract \Reviews")
End Sub
Sub ExtractArchive_ Global(ByVal strPath As String)
Dim strException As String
Dim sourceDir As String
Dim destDir As String
Dim RenameDir As String
Dim StrFileName As String
Dim StrDir As String
Dim zipFilename As String
Dim ExtractDir As String
If Directory.Exist s(strPath) = False Then
Directory.Creat eDirectory(strP ath)
End If
Try
sourceDir = strPath & "\pwr"
RenameDir = strPath & "\pwr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
destDir = strPath & "\Archive\p wr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
If Directory.Exist s(sourceDir) Then
System.IO.Direc tory.Move(sourc eDir, RenameDir)
If Directory.Exist s(destDir) Then
System.IO.Direc tory.Delete(des tDir, True)
End If
System.IO.Direc tory.Move(Renam eDir, destDir)
End If
zipFilename = strPath & "\pwr.zip"
ExtractDir = strPath
Dim Redo As Integer = 1
Dim MyZipInputStrea m As ZipInputStream
Dim MyFileStream As FileStream
MyZipInputStrea m = New ZipInputStream( New FileStream(zipF ilename, _
FileMode.Open, FileAccess.Read ))
Dim MyZipEntry As ZipEntry = MyZipInputStrea m.GetNextEntry
System.IO.Direc tory.CreateDire ctory(ExtractDi r)
While Not MyZipEntry Is Nothing
If (MyZipEntry.IsD irectory) Then
Try
System.IO.Direc tory.CreateDire ctory(ExtractDi r & "\" & MyZipEntry.Name )
Catch ex As Exception
End Try
Else
Dim _strPath As String
Try
If Not System.IO.Direc tory.Exists(Ext ractDir & "\" & _
System.IO.Path. GetDirectoryNam e(MyZipEntry.Na me)) Then
_strPath = System.IO.Path. GetDirectoryNam e(MyZipEntry.Na me)
System.IO.Direc tory.CreateDire ctory(ExtractDi r & "\" & _strPath)
End If
Catch ex As ThreadAbortExce ption
Thread.ResetAbo rt()
End Try
Try
MyFileStream = New System.IO.FileS tream(ExtractDi r & "\" & _
MyZipEntry.Name , FileMode.OpenOr Create, FileAccess.Writ e)
Dim count As Integer
Dim buffer(50000) As Byte
count = MyZipInputStrea m.Read(buffer, 0, 50000)
While count > 0
MyFileStream.Wr ite(buffer, 0, count)
count = MyZipInputStrea m.Read(buffer, 0, 50000)
End While
buffer = Nothing
MyFileStream.Cl ose()
Catch ex As Exception
End Try
End If
MyZipEntry = MyZipInputStrea m.GetNextEntry
End While
If Not (MyZipInputStre am Is Nothing) Then
MyZipInputStrea m.Close()
End If
If Not (MyFileStream Is Nothing) Then
MyFileStream.Cl ose()
End If
Catch ex As ThreadAbortExce ption
Thread.ResetAbo rt()
End Try
End Sub[/code]