Skip to content

Commit

Permalink
MainWindow.xaml.cs: call WmiUtils.GetAvailablePhysicalMemory() only once
Browse files Browse the repository at this point in the history
On systems with large amount of memory, WmiUtils.GetAvailablePhysicalMemory
is noticeably slow, so avoid calling it twice when adding a new task.

Signed-off-by: akarin <[email protected]>
  • Loading branch information
AkarinVS committed May 4, 2021
1 parent 806337b commit cf5deda
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions OKEGui/OKEGui/Gui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ private void BtnNew_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(TxtFreeMemory.Text))
{
if (WmiUtils.GetAvailablePhysicalMemory() < 0)
int availMB = WmiUtils.GetAvailablePhysicalMemory();
if (availMB < 0)
{
MessageBox.Show("无法获取当前空闲内存!请自行检查当前可用内存。", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
}
else if (int.Parse(TxtFreeMemory.Text) < WmiUtils.GetAvailablePhysicalMemory())
else if (int.Parse(TxtFreeMemory.Text) < availMB)
{
Initializer.Config.memoryTotal = WmiUtils.GetTotalPhysicalMemory();
}
Expand Down

0 comments on commit cf5deda

Please sign in to comment.