小弟是初学者,可能对问题的描述不是太清晰,各位见谅。
我基本实现了自动拍照这个功能。但是有2个问题无法解决,请高手帮忙。1 我想中断自动拍照的循环,需要通过1个事件把标志位bflg设成true。但是我要如何把这个事件绑定起来?(拍照窗口其实内置了1个退出事件,但是我怎么和自己的代码联系起来,拍照窗口不是我自定义的。)2 在调用拍照窗口进行自动拍照的过程中,如果不停的点击触摸屏会随机造成手机死机,停在照相窗口无法退出或者拍照,只能重新启动手机才恢复正常。下面是部分代码。//跳出循环flag
Boolean bflg = false;
...while (bflg == false)
{
//cameraCapture.DefaultFileName = System.DateTime.Now.ToString("yyMMddHHmmss") + "." + imageFormatTmp;
cameraCapture.DefaultFileName = System.DateTime.Now.ToString("yyMMddHHmmss") + ".jpg"; object someState = new object();
TimerCallback tmrClbck1 = new TimerCallback(this.atTimer1);
tmr = new System.Threading.Timer(tmrClbck1, someState, 2 * 1000, Timeout.Infinite); // Displays the "Camera Capture" dialog box
if (cameraCapture.ShowDialog() == DialogResult.OK)
{
string fileName = cameraCapture.FileName;
string buffer = "1111111";
WriteGpsInfoInXML(fileName, buffer);
} this.atTimer3(imageIntervalTimeTmp);
}private void atTimer1(object state)
{
try
{
IntPtr hwnd = GetForegroundWindow();
SendMessage(hwnd, 0x00000111, 0x00001BE8, 0x7C07FBD0); object someState = new object();
TimerCallback tmrClbck = new TimerCallback(this.atTimer2);
tmr = new System.Threading.Timer(tmrClbck, someState, 2 * 1000, -1);
}
catch (Exception) {
if (tmr != null)
{
tmr.Dispose();
}
Application.Exit();
}
}private void atTimer2(object state)
{
try
{
IntPtr hwnd = GetForegroundWindow();
SendMessage(hwnd, 0x00000111, 0x00001B77, 0x7C09A360);
tmr.Dispose();
}
catch (Exception) {
if (tmr != null)
{
tmr.Dispose();
}
Application.Exit();
}
}private void atTimer3(string imageIntervalTimeTmp)
{
int tmpSecond = 10;
if (IntervalTime5.Equals(imageIntervalTimeTmp))
{
tmpSecond = 5;
}
else if (IntervalTime10.Equals(imageIntervalTimeTmp))
{
tmpSecond = 10;
}
System.Threading.Thread.Sleep(tmpSecond * 1000);
}
我基本实现了自动拍照这个功能。但是有2个问题无法解决,请高手帮忙。1 我想中断自动拍照的循环,需要通过1个事件把标志位bflg设成true。但是我要如何把这个事件绑定起来?(拍照窗口其实内置了1个退出事件,但是我怎么和自己的代码联系起来,拍照窗口不是我自定义的。)2 在调用拍照窗口进行自动拍照的过程中,如果不停的点击触摸屏会随机造成手机死机,停在照相窗口无法退出或者拍照,只能重新启动手机才恢复正常。下面是部分代码。//跳出循环flag
Boolean bflg = false;
...while (bflg == false)
{
//cameraCapture.DefaultFileName = System.DateTime.Now.ToString("yyMMddHHmmss") + "." + imageFormatTmp;
cameraCapture.DefaultFileName = System.DateTime.Now.ToString("yyMMddHHmmss") + ".jpg"; object someState = new object();
TimerCallback tmrClbck1 = new TimerCallback(this.atTimer1);
tmr = new System.Threading.Timer(tmrClbck1, someState, 2 * 1000, Timeout.Infinite); // Displays the "Camera Capture" dialog box
if (cameraCapture.ShowDialog() == DialogResult.OK)
{
string fileName = cameraCapture.FileName;
string buffer = "1111111";
WriteGpsInfoInXML(fileName, buffer);
} this.atTimer3(imageIntervalTimeTmp);
}private void atTimer1(object state)
{
try
{
IntPtr hwnd = GetForegroundWindow();
SendMessage(hwnd, 0x00000111, 0x00001BE8, 0x7C07FBD0); object someState = new object();
TimerCallback tmrClbck = new TimerCallback(this.atTimer2);
tmr = new System.Threading.Timer(tmrClbck, someState, 2 * 1000, -1);
}
catch (Exception) {
if (tmr != null)
{
tmr.Dispose();
}
Application.Exit();
}
}private void atTimer2(object state)
{
try
{
IntPtr hwnd = GetForegroundWindow();
SendMessage(hwnd, 0x00000111, 0x00001B77, 0x7C09A360);
tmr.Dispose();
}
catch (Exception) {
if (tmr != null)
{
tmr.Dispose();
}
Application.Exit();
}
}private void atTimer3(string imageIntervalTimeTmp)
{
int tmpSecond = 10;
if (IntervalTime5.Equals(imageIntervalTimeTmp))
{
tmpSecond = 5;
}
else if (IntervalTime10.Equals(imageIntervalTimeTmp))
{
tmpSecond = 10;
}
System.Threading.Thread.Sleep(tmpSecond * 1000);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货