基于 Mint 提供的 VM 跟踪代码,我为我的应用程序制作了一种“早期警告”系统,当 VM 接近将开始导致问题的点时会向您发出警告并建议重新启动。这有点烦人,但除非有人想出一个更好的解决方案来解决在 64 位操作系统环境中运行的 32 位 Office,否则它必须这样做。
ReturnVM:返回以 GB 为单位的虚拟内存使用情况,如果超过 1.425GB,则触发警报。我发现这适用于我的应用程序,在重新启动之间给予尽可能多的时间,同时仍然允许在重新启动之前完成工作。随时根据需要进行调整。
os_Restart:编写一个批处理文件,杀死活动的 Access 进程,删除剩余的 laccdb 文件并重新启动应用程序(假设一切都在用户的桌面上)。写入文件后,它执行批处理。另一个函数在应用程序启动时删除此文件。
TempVars!tv_WinUID = 环境(“用户名”)
Function ReturnVM() As Double
Dim Mem As MEMORYSTATUS
Dim Result As Integer
Mem.dwLength = Len(Mem)
GlobalMemoryStatus Mem
ReturnVM = Format((Mem.dwTotalVirtual - Mem.dwAvailVirtual) / 1073741824, "0.000")
Debug.Print ReturnVM & " GB of VM used."
If (ReturnVM >= 1.425) Then
DoEvents
Result = MsgBox("Office Virtual Memory usage is approaching the pre-set limit." & vbCrLf & vbCrLf & "To prevent a possible crash, please click 'OK' to restart immediately." & vbCrLf & vbCrLf & "You may click 'Cancel' to finish what you're working on, but if you do, please restart the application as soon as possible.", vbOKCancel)
If (Result = vbOK) Then
os_Restart
End If
End If
End Function
Public Function os_Restart()
Dim fso As Object
Dim oFile As Object
Dim BatchContents As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile("C:\Users\" & TempVars!tv_WinUID & "\Desktop\RestartAccess.bat")
BatchContents = "@echo Restarting Application..." & vbCrLf & _
"@echo off" & vbCrLf & _
"taskkill /f /im MSACCESS.EXE" & vbCrLf & _
"ping -n 6 127.0.0.1 > nul" & vbCrLf & _
"del " & Chr(34) & "C:\Users\" & TempVars!tv_WinUID & "\Desktop\Application.laccdb" & Chr(34) & vbCrLf & _
"start " & Chr(34) & Chr(34) & " " & Chr(34) & "C:\Users\" & TempVars!tv_WinUID & "\Desktop\Application.accdb" & Chr(34)
DoEvents
'Debug.Print BatchContents
oFile.WriteLine BatchContents
oFile.Close
Set fso = Nothing
Set oFile = Nothing
Call Shell("C:\users\" & TempVars!tv_WinUID & "\Desktop\RestartAccess.bat")
End Function