我的應用程序只是簡單的sendkeys。我的問題是當我運行我的應用程序時,它用於大約55-65k的內存使用量,然後當我最小化到系統托盤時,它突然下降到大約1-3k的內存使用量,然後當我恢復它時,它上升到約6-8k的內存使用量。我的問題是我怎麼能降低內存使用量,即使我沒有最小化我的應用程序?vb.net內存使用
注:我試圖等待大約3分鐘,看看我的應用程序是否會減少它的內存使用情況,因爲我認爲它只是加載一些組件。但我沒有,我坐在55-65k,如果我不把它最小化。
這裏是我的代碼:
Imports System.Runtime.InteropServices
Imports System.Threading
Public Class Form1
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
Public Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow"() As IntPtr
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private SearchWindow As String
Public Const vbKeyQ = 81
Public Const vbKeyW = 87
Public Const vbKeyE = 69
Public Const vbKeyR = 82
Public Const KEYEVENTF_KEYUP = &H2
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SearchWindow = "MU"
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Control.IsKeyLocked(Keys.CapsLock) Then
Dim ForeGroundHwnd As IntPtr = GetForegroundWindow
Dim MySearchWinow As IntPtr = FindWindow(Nothing, SearchWindow)
If ForeGroundHwnd = MySearchWinow Then
If rbQ.Checked = True Then
keybd_event(vbKeyQ, 0, 0, 0)
keybd_event(vbKeyQ, 0, KEYEVENTF_KEYUP, 0)
ElseIf rbW.Checked = True Then
keybd_event(vbKeyW, 0, 0, 0)
keybd_event(vbKeyW, 0, KEYEVENTF_KEYUP, 0)
ElseIf rbE.Checked = True Then
keybd_event(vbKeyE, 0, 0, 0)
keybd_event(vbKeyE, 0, KEYEVENTF_KEYUP, 0)
ElseIf rbR.Checked = True Then
keybd_event(vbKeyR, 0, 0, 0)
keybd_event(vbKeyR, 0, KEYEVENTF_KEYUP, 0)
End If
End If
End If
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Try
If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Minimized
NotifyIcon1.Visible = True
Me.Hide()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Try
Me.Show()
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
End Class