none
vb2005编译后程序运行超占内存,该如何解决? RRS feed

  • 问题

  •  

    自己用vb2005写了个小程序,可是编译后运行,占用内存达12MB,本以为是自己的代码写的不好,于是我新建了一个windows应用程序项目,不添加任何代码直接编译,运行后占内存达11MB,请问这种现象正常吗,反正我觉得很不正常,应该如何操作才能使编译后的程序少占内存?请高手明示,谢谢了!

        以下是代码,请高手帮我看看,如何修改,能提高效率,少占内存?

    Public   Class   ManiGUI
            Dim   SelectedFileName   As   String   =   ""
            Dim   SelectedFilePatch   As   String   =   ""
            Dim   SelectedFileProcess   As   Process()


            Private   Sub   notifyicon1_Doubleclick(ByVal   sender   As   Object,   ByVal   e   As   System.EventArgs)   Handles   NotifyIcon1.DoubleClick
                    Me.Show()
                    Me.WindowState   =   FormWindowState.Normal
                    Me.Activate()
            End   Sub   '双击恢复

            Private   Sub   SelectFile_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   SelectFile.Click
                    OpenFileDialog1.ShowDialog()
            End   Sub

            Private   Sub   OpenFileDialog1_FileOk(ByVal   sender   As   System.Object,   ByVal   e   As   System.ComponentModel.CancelEventArgs)   Handles   OpenFileDialog1.FileOk
                    SelectedFilePatch   =   OpenFileDialog1.FileName
                    SelectedFileName   =   System.IO.Path.GetFileNameWithoutExtension(OpenFileDialog1.SafeFileName)
                    If   SelectedFileName   <>   ""   Then
                            StarToWatch.Enabled   =   True
                    End   If
            End   Sub

            Private   Sub   Quit_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Quit.Click
                    Me.NotifyIcon1.Visible   =   False
                    Me.Close()
                    Me.Dispose()
                    System.Environment.Exit(System.Environment.ExitCode)
                    Application.Exit()
            End   Sub

            Private   Sub   StarToWatch_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   StarToWatch.Click
                    Timer1.Enabled   =   True
                    Me.NotifyIcon1.BalloonTipText   =   "正在守护     "   +   SelectedFileName
                    NotifyIcon1.ShowBalloonTip(30)
                    Me.Hide()
            End   Sub

            '最小化缩到右下角  
            Private   Sub   ManiGUI_Load(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   MyBase.SizeChanged

                    If   Me.WindowState   =   FormWindowState.Minimized   Then
                            If   SelectedFileName   =   ""   Then
                                    Me.NotifyIcon1.BalloonTipText   =   "守护进程"
                            Else
                                    Me.NotifyIcon1.BalloonTipText   =   "正在守护     "   +   SelectedFileName
                            End   If
                            NotifyIcon1.ShowBalloonTip(30)
                            Me.Hide()
                    End   If
            End   Sub


            Private   Sub   Timer1_Tick(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Timer1.Tick
                    SelectedFileProcess   =   Process.GetProcessesByName(SelectedFileName)
                    If   SelectedFileProcess.Length   >   0   Then
                            Return
                    Else
                            Dim   SelectedFileProcess1   As   New   Process
                            SelectedFileProcess1.StartInfo.FileName   =   SelectedFilePatch
                            SelectedFileProcess1.Start()
                    End   If
            End   Sub
            Private   Sub   显示ToolStripMenuItem_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   显示ToolStripMenuItem.Click
                    Me.Show()
                    Me.WindowState   =   FormWindowState.Normal
                    Me.Activate()
            End   Sub

            Private   Sub   退出ToolStripMenuItem_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   退出ToolStripMenuItem.Click
                    Me.NotifyIcon1.Visible   =   False
                    Me.Close()
                    Me.Dispose()
                    System.Environment.Exit(System.Environment.ExitCode)
                    Application.Exit()
            End   Sub
    End   Class
    Public   Class   ToolStripMenuItem


    End   Class
    2008年1月21日 2:16

答案

全部回复