473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Threading problem.

Hi all
I am having problem at a time of handling threading.
I am having application containing thread.
In thread procedure i ma using recursive function.
This recursive function is adding some entries in my temprary file.
But when i called abort on thread it is not aborting that thread.
After calling aborting still entries are getting inserted into
temporary files.
That means still recursive function is getting executed.
Can some one tell me why this is happening even after calling abort on
thread.
Is there any alternative for aborting thread.
Please help me as this is very very important for me.

Thanks in advance.

Nov 21 '05 #1
6 1275
Of course we can help, but we need to see some code to see where you're
going wrong

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2
tr**************@yahoo.com schrieb:
Hi all
I am having problem at a time of handling threading.
I am having application containing thread.
In thread procedure i ma using recursive function.
This recursive function is adding some entries in my temprary file.
But when i called abort on thread it is not aborting that thread.
After calling aborting still entries are getting inserted into
temporary files.
That means still recursive function is getting executed.
Can some one tell me why this is happening even after calling abort on
thread.
Is there any alternative for aborting thread.
Please help me as this is very very important for me.

Thanks in advance.


Don't call abort. Use your own abort mechanism. I prefer passing an object
containing a Cancel flag that can be set by a client thread and checked by
the executing thread. Example:

class CancelClass
cancel as boolean
end class

Pass an object (called 'o' here) of this type to the thread. The thread
checks o.cancel from time to time (at a good place in a loop) to see if it
is to be canceled. In the main/other thread, you can set o.cancel=true
instead of calling abort.

Armin
Nov 21 '05 #3

hello
thanks for your reply.
i am sending general structure of my classes and function as below:-
if u get some idea please help me.
I have form on which i have two buttons.

On one button i have code like:-
objs = new scanning
objs.Main()

on another button i have code like
objs.threadsynch.abort
which is not aborting synch thread.
class Scanning
Public Sub Main()
dim objcls as new scan
threadsynch=new thread(addressof objcls.startscan
threadsynch.start()
end sub
end class

class Scan
public function startscan()
' contains someactual code for scanning
'''some extra code
scanWithSubDirs
''''some extra code
end function

Public Function scanWithSubDirs()

' actual scanning is donw here which contains one recursive function

travresebothDir()

end function
Private Function travresebothDir()szLocalPath As String, ByVal
bDirExists As Boolean)
''is recursive function which is traversing two local directores and
writing simiarler filename in file
Dim dirInfo As System.IO.DirectoryInfo

If szLocalPath.EndsWith(":") Then
dirInfo = New System.IO.DirectoryInfo(szLocalPath & "\")
Else
dirInfo = New System.IO.DirectoryInfo(szLocalPath)
End If
Dim fInfo As System.IO.FileInfo
Dim eachDirInfo As System.IO.DirectoryInfo
For Each eachDirInfo In dirInfo.GetDirectories("*")
oftp.FTPChangeDirectory(eachDirInfo.Name)
objDir = objFTP.GetDirectoryListing()
travresebothDir(eachDirInfo.FullName, True)
writeSynchrItem("temp.txt", szAddDir)
travresebothDir(eachDirInfo.FullName, False)
next

end function
end class

Nov 21 '05 #4
Hi
thanks for your reply.
But can you tell me reason behing not using abort method.
as calling abort is throwing exception where i can release all
resources.
Because problem is i have used abort at many places and not chaning it
to flag is becoming difficule for me.
So can u explaing me reason behind not using abort method.

thansk

Nov 21 '05 #5
tr**************@yahoo.com schrieb:
Hi
thanks for your reply.
But can you tell me reason behing not using abort method.
as calling abort is throwing exception where i can release all
resources.
Because problem is i have used abort at many places and not chaning it
to flag is becoming difficule for me.
So can u explaing me reason behind not using abort method.

thansk


Why crash the car instead of braking and stopping at the right (or left)
side? Abort is the hard way to stop a thread. I prefer to have better
control over it, thus the suggestion to use a signal object.

To answer your question: I can not reproduce the problem. If I call the
abort method of a thread doing recursive function calls, the thread is also
aborted, i.e. the Threadabortexception is raised. In general, it shouldn't
matter whether the calls are recursive. Maybe your own code handles the
exception in a way that prevents you from stopping the thread. (How) do you
handle the exception?

Armin
Nov 21 '05 #6
Abort can also be problematic if you are making use of COM objects in your
thread, causing strange exceptions regurgitated from the innermost depths of
windows that are difficult to reproduce and impossible to "fix". Don't use
Abort, unless you mean "URGENT! STOP NOW!". I suspect what you really mean
is "Please make an effort to stop now, if you don't mind; whenever you think
it's convienient to do so.".

Threading: be gentle (use a "bStopping" flag).


Robin
<tr**************@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi
thanks for your reply.
But can you tell me reason behing not using abort method.
as calling abort is throwing exception where i can release all
resources.
Because problem is i have used abort at many places and not chaning it
to flag is becoming difficule for me.
So can u explaing me reason behind not using abort method.

thansk

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
17
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next...
2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
11
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
5
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.