473,729 Members | 2,096 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 1314

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
3030
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
9142
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
5090
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
8927
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
9428
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...
1
9210
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,...
1
6722
isladogs
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...
0
6026
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();...
0
4534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2694
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
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.