我目前正在开发一个程序,用于一次记录多层素材。我目前正在使用此方法截屏:
for (var i = 0;; i++)
{
SendKeys.SendWait(" ");
p.Send(greenscreen);
string str = "";
Graphics memoryGraphics2 = Graphics.FromImage(memoryImage);
memoryGraphics2.CopyFromScreen(0, 0, 0, 0, s);
str = string.Format(Path.GetDirectoryName(Application.ExecutablePath) + "//regular//" +
$@"\regular{i}.png");
memoryImage.Save(str);
System.Threading.Thread.Sleep(200);
p.Send(regular2);
string str2 = "";
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);
str2 = string.Format(Path.GetDirectoryName(Application.ExecutablePath) + "//green//" +
$@"\green{i}.png");
memoryImage.Save(str2);
System.Threading.Thread.Sleep(200);
SendKeys.SendWait(" ");
p.Send(greenscreen);
System.Threading.Thread.Sleep(200);
p.Send(regular2);
System.Threading.Thread.Sleep(200);
}
但是,我目前正在使用Thread.Sleep运行所有程序。取而代之的是,可以确保在继续进行下一部分之前已截取屏幕截图吗?例如:
memoryImage.Save(str);
System.Threading.Thread.Sleep(200);
p.Send(regular2);
您可以看到它保存了屏幕截图,然后休眠,然后执行我的下一个命令。我该怎么做,所以不用睡觉,而是要确保在继续之前已经截取了屏幕截图?