VB.NET Winforms application showing high memory use?

Tech tipsComputer Tricks

Purpose : When designing Windows form applications, you can use the code below to minimize the amount of memory Task Manager shows your application is using.

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

    Shared Sub ReleaseMemory()
        Try
            GC.Collect()
            GC.WaitForPendingFinalizers()
            If Environment.OSVersion.Platform = PlatformID.Win32NT Then
                SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1)
            End If
        Catch
        End Try
    End Sub

Send Email from Code Behind

Tech tipsComputer Tricks

Purpose : To allow webpage to send an email.

Special Note : Requires additional code in web.config

    Public Function sendEmail(ByVal myTo As String, ByVal mySubject As String, Optional ByVal myBody As String = "") As Boolean
        Dim myReturn As Boolean = False

        Try
            Dim myEmail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
            Dim smtpClient As New System.Net.Mail.SmtpClient

            myEmail.Body = myBody
            myEmail.Subject = mySubject
            myEmail.To.Add(myTo)
            'myEmail.Bcc.Add("userToBCC@yourdomain.com")
            smtpClient.Send(myEmail)

            myReturn = True  ' The function has completed with NO errors

        Catch ex As Exception
            'Handle Error
            Return False

        End Try

        Return myReturn
    End Function

CODE FOR WEB.CONFIG FILE


  <system.net>

    <mailSettings>

      <smtp>

        <network host="relay-hosting.secureserver.net" />

      </smtp>

    </mailSettings>

  </system.net>