473,748 Members | 4,067 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread abort exception when running timer.

1 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As   System.EventArgs) Handles MyBase.Load
  2.         fnInitiateZipTimer()
  3.        Thread.Sleep(-1)
  4. End Sub
  5.  
  6.  Private Sub objTimer_Elapsed(ByVal sender As Object, ByVal e As            System.Timers.ElapsedEventArgs) Handles objTimer.Elapsed
  7.        ExtractArchive_Global("F:\Projects\ZipExtract\Reviews")
  8.  End Sub
  9.  
  10. Sub ExtractArchive_Global(ByVal strPath As String)
  11.         Dim strException As String
  12.         Dim sourceDir As String
  13.         Dim destDir As String
  14.         Dim RenameDir As String
  15.         Dim StrFileName As String
  16.         Dim StrDir As String
  17.         Dim zipFilename As String
  18.         Dim ExtractDir As String
  19.         If Directory.Exists(strPath) = False Then
  20.             Directory.CreateDirectory(strPath)
  21.         End If
  22.         Try
  23.             sourceDir = strPath & "\pwr"
  24.             RenameDir = strPath & "\pwr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
  25.             destDir = strPath & "\Archive\pwr-" & Format(Now(), "yyyy-MM-dd-hh-mm")
  26.             If Directory.Exists(sourceDir) Then
  27.                 System.IO.Directory.Move(sourceDir, RenameDir)
  28.                 If Directory.Exists(destDir) Then
  29.                     System.IO.Directory.Delete(destDir, True)
  30.                 End If
  31.                 System.IO.Directory.Move(RenameDir, destDir)
  32.             End If
  33.             zipFilename = strPath & "\pwr.zip"
  34.             ExtractDir = strPath
  35.             Dim Redo As Integer = 1
  36.             Dim MyZipInputStream As ZipInputStream
  37.             Dim MyFileStream As FileStream
  38.             MyZipInputStream = New ZipInputStream(New FileStream(zipFilename, _
  39.               FileMode.Open, FileAccess.Read))
  40.             Dim MyZipEntry As ZipEntry = MyZipInputStream.GetNextEntry
  41.             System.IO.Directory.CreateDirectory(ExtractDir)
  42.             While Not MyZipEntry Is Nothing
  43.                 If (MyZipEntry.IsDirectory) Then
  44.                     Try
  45.                         System.IO.Directory.CreateDirectory(ExtractDir & "\" & MyZipEntry.Name)
  46.                     Catch ex As Exception
  47.                     End Try
  48.                 Else
  49.                     Dim _strPath As String
  50.                     Try
  51.                         If Not System.IO.Directory.Exists(ExtractDir & "\" & _
  52.                         System.IO.Path.GetDirectoryName(MyZipEntry.Name)) Then
  53.  
  54.                             _strPath = System.IO.Path.GetDirectoryName(MyZipEntry.Name)
  55.                             System.IO.Directory.CreateDirectory(ExtractDir & "\" & _strPath)
  56.                         End If
  57.                     Catch ex As ThreadAbortException
  58.                         Thread.ResetAbort()
  59.                     End Try
  60.                     Try
  61.                         MyFileStream = New System.IO.FileStream(ExtractDir & "\" & _
  62.                      MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write)
  63.                         Dim count As Integer
  64.                         Dim buffer(50000) As Byte
  65.                         count = MyZipInputStream.Read(buffer, 0, 50000)
  66.                         While count > 0
  67.                             MyFileStream.Write(buffer, 0, count)
  68.                             count = MyZipInputStream.Read(buffer, 0, 50000)
  69.                         End While
  70.                         buffer = Nothing
  71.                         MyFileStream.Close()
  72.                     Catch ex As Exception
  73.                     End Try
  74.                 End If
  75.                 MyZipEntry = MyZipInputStream.GetNextEntry
  76.             End While
  77.             If Not (MyZipInputStream Is Nothing) Then
  78.                 MyZipInputStream.Close()
  79.             End If
  80.             If Not (MyFileStream Is Nothing) Then
  81.                 MyFileStream.Close()
  82.             End If
  83.         Catch ex As ThreadAbortException
  84.             Thread.ResetAbort()
  85.         End Try
  86.    End Sub
Aug 2 '07 #1
0 1315

Sign in to post your reply or Sign up for a free account.

Similar topics

0
392
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...
7
3292
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...
20
3031
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...
7
9146
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...
18
5858
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.
0
2474
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()
5
2126
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?
20
5095
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
3
3180
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...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
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,...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
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...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
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...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.