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. -
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
fnInitiateZipTimer()
-
Thread.Sleep(-1)
-
End Sub
-
-
Private Sub objTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles objTimer.Elapsed
-
ExtractArchive_Global("F:\Projects\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.Exists(strPath) = False Then
-
Directory.CreateDirectory(strPath)
-
End If
-
Try
-
sourceDir = strPath & "\pwr"
-
RenameDir = strPath & "\pwr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
-
destDir = strPath & "\Archive\pwr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
-
If Directory.Exists(sourceDir) Then
-
System.IO.Directory.Move(sourceDir, RenameDir)
-
If Directory.Exists(destDir) Then
-
System.IO.Directory.Delete(destDir, True)
-
End If
-
System.IO.Directory.Move(RenameDir, destDir)
-
End If
-
zipFilename = strPath & "\pwr.zip"
-
ExtractDir = strPath
-
Dim Redo As Integer = 1
-
Dim MyZipInputStream As ZipInputStream
-
Dim MyFileStream As FileStream
-
MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, _
-
FileMode.Open, FileAccess.Read))
-
Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
-
System.IO.Directory.CreateDirectory(ExtractDir)
-
While Not MyZipEntry Is Nothing
-
If (MyZipEntry.IsDirectory) Then
-
Try
-
System.IO.Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
-
Catch ex As Exception
-
End Try
-
Else
-
Dim _strPath As String
-
Try
-
If Not System.IO.Directory.Exists(ExtractDir & "\" & _
-
System.IO.Path.GetDirectoryName(MyZipEntry.Name)) Then
-
-
_strPath = System.IO.Path.GetDirectoryName(MyZipEntry.Name)
-
System.IO.Directory.CreateDirectory(ExtractDir & "\" & _strPath)
-
End If
-
Catch ex As ThreadAbortException
-
Thread.ResetAbort()
-
End Try
-
Try
-
MyFileStream = New System.IO.FileStream(ExtractDir & "\" & _
-
MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
-
Dim count As Integer
-
Dim buffer(50000) As Byte
-
count = MyZipInputStream.Read(buffer, 0, 50000)
-
While count > 0
-
MyFileStream.Write(buffer, 0, count)
-
count = MyZipInputStream.Read(buffer, 0, 50000)
-
End While
-
buffer = Nothing
-
MyFileStream.Close()
-
Catch ex As Exception
-
End Try
-
End If
-
MyZipEntry = MyZipInputStream.GetNextEntry
-
End While
-
If Not (MyZipInputStream Is Nothing) Then
-
MyZipInputStream.Close()
-
End If
-
If Not (MyFileStream Is Nothing) Then
-
MyFileStream.Close()
-
End If
-
Catch ex As ThreadAbortException
-
Thread.ResetAbort()
-
End Try
-
End Sub
0 1310 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dan S |
last post by:
I am using a third party DLL which is the interface to an off-the-shelf
document management system (so I have to use it). Unfortunately it is very
poor and if there is a problem with the server, calls to this DLL simply hang
(on the order of 5 minutes). When this occurs that means there is a problem
with the Server and I need to communicate back to the consumers of my Web
Service this is the case. Basically, I need to set some kind of...
|
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 any point in the thread. In fact, I have a section of code needs to be "protected" from being interrupted. How can I make sure Abort() will not land anywhere winthin this block? In other words, the Abort() must wait until this block of code is done...
|
by: Doug Thews |
last post by:
I ran into an interesting re-pain delay after calling the Abort() method on
a thread, but it only happens the very first time I call it. Every time
afterward, there is no delay.
I've got a delegate inside the UI that I call to update the progress meter.
I use the Suspend() and Abort() methods based on button events.
I can watch the progress meter increase just fine when the thread is
running. When I select Start, I enable the Cancel...
|
by: Doug Thews |
last post by:
I saw something interesting when testing my multi-threaded code to make sure
that threads were terminating as I expected. When I first bring up my
WinForms test application (before I do any Thread.Start), I notice that my
process has 4 threads initially. Does anyone know what the other 3 threads
in my app's process are for?
Also, I posted a question earlier about getting an initial delay after
calling Thread.Abort (yes, I know it's not...
|
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 component becomes instabile, throwing a
Windows like error (access violation on 0x00000002), not an framework
exception. The component and all of its subcomponents are 100% managed code.
What could go wrong with Thread.Abort()?
Thanks for any hints.
| |
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 StopReader() method that simply aborts the worker thread (is
there a better way for the above situation?).
The StopReader creates an ObjectDisposedException when calling t.Abort(). WHY?
Public Sub StopReader()
|
by: John A. Bailo |
last post by:
From a Windows service (NET 2.0) I want to launch serveral threads in
a for loop that invokes a method using:
new Thread(delegate()
{ myMethod(248);}).Start();
Will those threads stay active even when the service reaches it Service
Timer Stop?
|
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= |
last post by:
John Dohn wrote:
When I do this, I put a special value in the queue (like None) and in
the worker thread, check for the special value and exit if found.
Threads can also be marked as "daemon threads" (see docs for
threading.Thread objects). This will make the application terminate if
only "daemon threads" are left.
So best would probably be soemthing like
|
by: yeye.yang |
last post by:
hey everybody
Does everybody can help me or give me some advise for the cross thread
exception catch
Here is what I want to do:
I have 2 classes "Scenario" and "Step", which have a
System.Thread.Timer for each to control their timeout gestion, in my
"main program", I start the "Scenario" and "Step", and I do something
between "StepStart" and "StepStop", when "Scenario" or "Step" timeout
expired, they raise an "exception", then my "main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |