我现在运行程序的时候界面死掉了,但进程并没有死。应该用多线程,对吧。大家看看我的疑问:
有一方法如下:
static void SetValue(double x,double y)
{
  ………………此处代码省略
}
现在我在一个button的click事件中调用了这个方法,我想用线程来处理这个的
 private void button1_Click(object sender, EventArgs e)
{
  thread t=new thread(SetValue);
  t.start();
}
我知道这是不行的,因为setvalue方法有参数传递,但是我该怎么写呢才能正确运行,谢谢各位了

解决方案 »

  1.   

            struct xx
            {
                public double x, y;
                public string z;
            }
            private void SetValue(object obj)
            {
                xx x = (xx)obj;
            }        private void button1_Click(object sender, EventArgs e)
            {
                System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(SetValue));
                xx x = new xx();
                x.x = 1;
                x.y = 2;
                x.z = "3";
                t.Start(x);
            }
      

  2.   

    线程传递参数
    Thread th = new Thread(new ParameterizedThreadStart(method));
    th.Start("参数"));
    private void method(string s)
    {}
    public Thread(
      ParameterizedThreadStart start
    )
    public delegate void ParameterizedThreadStart(
      Object obj
    )void Test(object o)
      {
      Console.WriteLine(o.ToString());
      }
      void StartThreads()
      {
      System.Threading.ThreadPool.QueueUserWorkItem(Test, 1);  
      new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Test)).Start("a");
      }
      

  3.   

    t.IsBackground = true;
    试试,感觉应该有什么东西阻塞了,再查查
      

  4.   

    我想问
    private void SetValue(object obj)
            {
                xx x = (xx)obj;
            }
    这个方法里面,我原先放置了一些语句在里面,实现了一些功能,现在只能放xx x = (xx)obj;这样的语句是不是,那我其他语句放在哪儿
      

  5.   

    还是可以放到SetValue里,但涉及界面的要使用委托
      

  6.   

    多谢啦,我现在弄出来了,但是有个问题,我想让线程start之后就运行,而不是等待操作系统分配运行,该用什么语句?