Threading problem

harvid

Member
Joined
Dec 8, 2004
Messages
18
Programming Experience
1-3
hello,

In my project i'm having a seperate class(Memory) for reducing the memory consumption function. I'm not able to create and start the threading concept. I used the following coding to create the thread but it shows me an error in the addressof operator stating that " Signature of Savememory function doesn't suits with Threadstart delegate signature. "

'This class utilizes the reduce memory function

Public Class Memory
Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal dwMinimumWorkingSetSize As Int32, ByVal dwMaximumWorkingSetSize As Int32) As Int32

Public Shared Function SaveMemory() As Int32
Return SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
End Function
End Class

I have written the code as follows:-

Imports System.Threading
Form1.vb
'Form1_Load
Dim mem As New Memory()
Dim t As New ThreadStart(AddressOf mem.SaveMemory)
Dim ts As New Thread(t)
ts.Start()
end sub

I don't know how to resolve these problem

Urgent
Pls help

Thanx in advance
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
The Delegate Sub ThreadStart is a sub procedure that doesn't return a value whereas Memory.SaveMemory is a Function that returns an Int32 value.
Are you planning on using the returned value?
If not, change the SaveMemory function to a sub.
If so, you'll have to create another procedure that calls the SaveMemory function and use that as the ThreadStart method.
 

harvid

Member
Joined
Dec 8, 2004
Messages
18
Programming Experience
1-3
The thread doesn't run till the application exit, it will run only once and stops( suppose in button click ). Is there any way to run continuosly?


How to incorporate a system.threading.timer class in my project such a way that the Savememory procedure run simultaneously with my application as a thread and wait for (sleep) every 10 minutes until i close my application.


Regards,
harry
 
Top Bottom