remove Handle of a thread

S

spielmann

Hello

I have a problem, a window display an hourglass during long
calculation.

For this I start a thread and close it when finished, but handles of
the dead thread stay in memory and increase...

Thanks for help and solution

Sample of the code:

******************************************************************

Public Class HourGlass
Protected Shared mLeave As Boolean = True
Protected Shared mThreadHourGlass As Threading.Thread
Protected Shared mFrmHourGlass As HGForm
Protected Shared mVisible As Boolean = True
Protected Shared mImage1 As Image =
Model.Image("hourglass1.bmp")
Protected Shared mImage2 As Image =
Model.Image("hourglass2.bmp")

Public Shared Sub Start()
If mThreadHourGlass Is Nothing OrElse
mThreadHourGlass.ThreadState = Threading.ThreadState.Stopped Then
mVisible = True
mThreadHourGlass = New Threading.Thread(AddressOf Run)
mThreadHourGlass.Name = "HourGlass.mThreadHourGlass"
mLeave = False
mThreadHourGlass.Priority =
Threading.ThreadPriority.BelowNormal
mThreadHourGlass.Start()
End If
End Sub

Public Shared Sub Show()
Start()
End Sub
Public Shared Sub Hide()
Close()
End Sub

Public Shared Sub Close()
mLeave = True
End Sub


Private Shared Sub Run()
mFrmHourGlass = New HGForm
Dim IsPic1 As Boolean = True
While Not mLeave AndAlso Not mFrmHourGlass Is Nothing
AndAlso Not mFrmHourGlass.forceClose
Application.DoEvents()
If IsPic1 Then
mFrmHourGlass.mPic.Image = mImage2
Else
mFrmHourGlass.mPic.Image = mImage1
End If
IsPic1 = Not IsPic1
Threading.Thread.Sleep(250)
End While
mFrmHourGlass.Dispose()
mFrmHourGlass = Nothing
End Sub
 
C

Cor Ligthert

Spielman,

You have made a complete shared program, I dont believe that the thread is
really a thread, it is just processing confirming the doevents. In my
opinion it is better to try first to make a program that is not completly
shared. Even when you find this the best approach than you are alone and
help for those things is difficult to get.

Just my thought,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top