[英]Application memory usage and looping
所以我正在尝试制作一个机器人应用程序,试图看看我如何在 c# 中做某些事情。 我不是想作弊,这是我在模拟器上运行的手机游戏。 这不是我试图出售或以任何方式从中获利的应用程序,这只是我学习如何做这些事情的任务。
无论如何,当我启动应用程序时,内存立即增加到 16 mb,而且我正在尝试进行循环,直到单击停止按钮。
我为每一个动作制作函数,我使用一个计时器来运行所有函数来扫描是否检测到一个像素,但应用程序运行缓慢并占用大量内存,我觉得这种“循环”是不是执行此类操作的正确方法,我也尝试过while
方法。
有谁愿意告诉我我在做什么?
private void timer1_Tick(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
// Checking if we entered Dragon's B10
if (inDungeon == false)
{
GoToDungeon();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2078, 61); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
StartBattle();
}
else
{
GoToDungeon();
}
// Starting auto-play
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2296, 969); // 0xFFFFFF
if (autoSumPoint == 0xFFFFFF)
{
AutoCheck();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2755, 489); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
PauseCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for victory
if (victoryChecked == false)
{
VictoryCheck();
}
// Checking for replay
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2602, 587); // 0xF3C761
if (autoSumPoint == 0xF3C761)
{
ReplayCheck();
}
// Checking for refill
if (energyRefilled == false)
{
RefillCheck();
}
}
}
我会考虑改变定时器的每个滴答之间的延迟,这样它就不会烧毁你的 CPU。
private void timer1_Tick(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
// Checking if we entered Dragon's B10
if (inDungeon == false)
{
GoToDungeon();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2078, 61); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
StartBattle();
}
else
{
GoToDungeon();
}
// Starting auto-play
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2296, 969); // 0xFFFFFF
if (autoSumPoint == 0xFFFFFF)
{
AutoCheck();
}
// Starting battle
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2755, 489); // 0xF1EECF
if (autoSumPoint == 0xF1EECF)
{
PauseCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for defeat
if (defeatChecked == false)
{
DefeatCheck();
}
// Checking for victory
if (victoryChecked == false)
{
VictoryCheck();
}
// Checking for replay
autoSumPoint = AutoIt.AutoItX.PixelGetColor(2602, 587); // 0xF3C761
if (autoSumPoint == 0xF3C761)
{
ReplayCheck();
}
// Checking for refill
if (energyRefilled == false)
{
RefillCheck();
}
}
System.Threading.Thread.Sleep(1000)//causes it to wait 1 second after each tick before the next one to reduce CPU usage
}
看看对你有没有帮助!
技术7 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.