有没有人做过类似 实时检测功能的,,当然这个不可以别人触发你,只可以你主动去探寻他  我做了个死循环  但是出现堆栈溢出错误,,有人帮解决下不如果可以 我想在当前循环的结尾加一个释放当前资源
主要引起这个原因的是  client.DownloadString(“URL”);  这句

解决方案 »

  1.   

    不建议用死循环, 就算用了也得有个sleep时间。
      

  2.   

    因为 后续还有一个语句调用 相机拍照  这个响应时间会在4秒左右
    所以用timer类好像麻烦一点,,,因为要在照相前 增加 timer.Enable=false
    然后照完了在 timer.Enable=true   至于我现在用的死循环  里边是存在 sleep(500) 的 所以延迟考虑了进去  我怕会造成堆栈错误
    在sleep(500)前  还有一个  GC.Collect();
    后便的代码才是 而 sleep(500) 后便的就是调用自身方法了当然  在跳出死循环控制方面 我是在  GC.Collect() 前边有一个判断变量  里边用 return() 跳出来的
      

  3.   

    没必要用Enable阿,直接加个bool型的变量作控制不就可以了,如果处于未响应状态,Timer触发的事件直接return即可
      

  4.   

    额,,那也就是把我刚才说的那个放 timer.Enable=false  和 timer.Enable=true
    替换成 bool变量  b=false  和 b=true 了,,貌似道理差不多额,,
    这样的话  大家的意思就是都觉得 用新的线程死循环控制  是不对的  应该用timer 控制 是吧?
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                client = new WebClient();
                client.DownloadStringCompleted+=new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
            }        WebClient client;
            private void button1_Click(object sender, EventArgs e)
            {
                //开始下载
                client.DownloadStringAsync(new Uri("http://www.baidu.com"));
            }        //下载完成后就会触发DownloadStringCompleted事件
            void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                //s就是此次下载得到的string内容,之后你就可以进行其它处理了
                string s = e.Result;            //开始下一次的下载
                client.DownloadStringAsync(new Uri("http://www.baidu.com"));
               
                System.Threading.Thread.Sleep(5000);
            }
        }
    }用异步下载来进行处理