-
November 16th, 2011, 10:03 PM
#1
Start new thread adds 4-6 handles
Check process handle count:
In Task manager, View, Select columns, mark Handle Count to the view.
=====================================================================
(The process when loaded has about 333 handles)
Operation:
The new thread is set equal to an existing thread, then the existing thread is started and aborted. How does one restore the old handle count? Why do the handles increase by a random number and do not revert?
How can Idisposable/CloseHandle/or GC.collect, Finalize() work in this situation? I'm trying to return the handles to their original count, 333, when I start a new thread it adds 4,5, or 6 handles per new thread(even if the thread is aborted and set to nothing).
1. Does this require manualresetevent or lock?
http://www.codeguru.com/forum/showth...t=handle+count
2. Is my code incorrect?
Code:
Public Class Form1
Dim thread1 As Threading.Thread
Dim started As Boolean
'=============================================
Private Sub starter()
If started = True Then
aborter()
Else
startnewthread()
End If
End Sub
'================================================
'=====================================================
Private Sub aborter()
thread1.Abort()
thread1 = Nothing
started = False
End Sub
'=============================================
Private Sub startnewthread()
Dim ntr As New Threading.Thread(AddressOf task)
thread1 = ntr
thread1.Start()
started = True
End Sub
''================================================
Private Sub task()
'Do things
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
starter()
End Sub
End Class
-
November 17th, 2011, 12:14 PM
#2
Re: Start new thread adds 4-6 handles
Windows schedules it's own tasks.
-
November 18th, 2011, 06:27 AM
#3
Re: Start new thread adds 4-6 handles
What do you mean by that? I'm sorry if I didn't understand.
-
November 18th, 2011, 12:52 PM
#4
Re: Start new thread adds 4-6 handles
Just watch the thread count when you start a program...
-
November 19th, 2011, 03:14 AM
#5
Re: Start new thread adds 4-6 handles
Yes I'm well aware of the thread count, it's fine.
I'm talking about the Handle count.
Code:
'Trying to regulate handle count using this code. It's pretty effective,
but only when there's a large amount of them.
' I try to do some worker threads to send items to another listview,
'but this method only reduces SOME of their occupied handles.
dim initialthread as threading.thread
dim bo as boolean
''''''''''''''''''''''''''''''''''''''
private sub loopop()
While True
threading.thread.sleep(100)
if process.getcurrentprocess.handlecount-1 >500 then
GC.collect
end if
End While
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''
private sub start()
If bo=false Then
dim tr as new thread(Addressof loopop)
initialthread=tr
initialthread.start
bo=true
end if
end sub
It continuously goes up and it has to go relatively high in order to clear itself(GC.collect), the problem sometimes is that only a small amount get cleared and the number of handles continue to grow.
Last edited by StriderH2; November 19th, 2011 at 03:34 AM.
-
November 19th, 2011, 04:01 PM
#6
Re: Start new thread adds 4-6 handles
Sleeping for 1 second is bound to add delays...
-
November 19th, 2011, 11:58 PM
#7
Re: Start new thread adds 4-6 handles
It sleeps for 100 milliseconds btw.
Anyway I think I've figured it out, thanks for trying.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|