Well I have some subs like:
Private Sub somesub() 'Processses that reach 900 mb in 1 hour and an half End Sub
I want to restart the app, dispose memory and then return to where I was.
Exactly, I have an app that adds contacts and well It reach 900mb when 2000 contacts are added... I want to stop every 200 contacts, and do that I have said, and the code that I have no tested:
Imports SKYPE4COMLib
Public Class frmMain
Dim pUser As SKYPE4COMLib.User
Dim contactos As Integer
If contactos < 200 Then
For Each oUser In ListBox1.Items
pUser = oSkype.User(oUser)
pUser.BuddyStatus = SKYPE4COMLib.TBuddyStatus.budPendingAuthorization
oSkype.Friends.Add(pUser)
contactos += 1
Next
Else
'System.Windows.Forms.Application.Restart()
'I need a code that continues where I was, here...
End If
End Sub
End Class
What can I do? Thanks!
I have written some code below that may solve your problem. It certainly should save your position to a file and then when the file runs again, it would reload that position.
A couple of points.
I moved your declaration of pUser, and set it to nothing when I was done. This way the object is marked for disposal immediately.. you might get more than 200 revolutions out of this with that structure change.. but it might be a tad slower.
You will need some sort of reload for your listbox. I assume that you did not include it as part of your sample for brevity.
I changed your foreach loop to a for loop structure. This allows you to track your position within the list .. as a result I had to create a new oUser since you were iterating that in the foreach and did not list its type, you will need to fix that part of the code.
Obviously I have not compiled the below code, but it should give you a decent start on what your trying to do.
Be careful of the Process.Start, as you can set the current process to start another process and wait for that process to exit before exiting the current one and that would be very very very very bad and really cause an OutOfMemoryException quickly. You need to let the current process start the next instance and then without checking to see if it was successful at starting it .. exit. Or if you have used the restart command in your comments use that. The process spawning method might do what your wanting more effectively because your starting a new process on the computer and letting the old one be garbage collected (thus releasing the resources it was using.