Windows Services and Threading

  • Thread starter Thread starter ermonnezzaro
  • Start date Start date
E

ermonnezzaro

Hi guys,

I am developing a windows services which periodically connects to a
database, fetches data in a dataset and do so work. I have chosen to
use a thread to do this job. Since the thread monitors the situations
every 2 hours, I put the thread in a sleep state. On my WinXp machine
everything works fine: memory grows to 200MB when loading data and goes
back to a normal state when I destroy the object. On a Win2003 server
things change a lot. When I start my service momory loaded is nearly
1Gb and it's never released. After few cicles it goes out of memory.
I am using a gc.collect before making the thread sleep ... but I am
scared of this. I was reading on few newgroup I could use a
Threading.Timer but I can't test this solution. Do you any idea?

Thanks

Alberto
 
Hi,

I really doubt Thread.Sleep can contribute to memory consuption. Look
elsewhere. Unfortunately without seeing the code, I cannot be more specific.

But - I'd definitely avoid GC.Collect. Just use Dispose as prescribed and do
not leave references to objects you no longer need (be especially careful
with delegates).
 
Thanks for your help Dmytro.
As I told you in my previous post the application works great on my
WindowsXp machine. Troubles come out when I try to run it on a Win 2003
Server biprocessor.
I use this code to create my main thread:

Try
_thProcessDocuments = New System.Threading.Thread(AddressOf
ProcessDocumentsThread)
_thProcessDocuments.Name = "ProcessDocuments"
_thProcessDocuments.Start()

Catch oException As System.Exception
bRet = False

Log.Logger.WriteException("_thCreateDocuments->[CreateDocumentsThread]",
oException, Log.Logger.LogTypes.Error, Me.GetType, "StartService")
End Try


and this is the procedure:

Private Sub ProcessDocumentsThread()

Do While (_Started)

' Do some work ...
Threading.Thread.CurrentThread.Slee(180 * 60000)

Loop

End Sub

I do lots of things in the loop but I always put to nothing everything
even when I could not do it, for example when my variables go out of
scope.
I have implemented IDispose in most of my classes and I alway dispose
and destroy everything.
What else I could check? ... and why I don't have the same result on a
WinXp machine?

Thanks in advance

Alberto
 
Back
Top