473,699 Members | 2,813 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 1310

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
3283
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
3017
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
9141
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
5847
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
2465
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
2124
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
5076
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
3179
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
8617
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
9035
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...
1
8914
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,...
0
7751
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...
1
6534
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
5875
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
4629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
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
3
2009
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.