1.线程封装到类里去,每次实例化一个,类里开线程,线程把返回值写入public类型的变量里,这样A就能获取到了
2.给线程注册回调函数(用委托)
3.不要用局部变量str,而是弄个全局数组,线程把结果直接写到全局数组里,这样你在工程的每个文件里都能获取它的值了

解决方案 »

  1.   

    看好楼主的代码里,确实的有个while(true),这样回调函数其实才是不靠谱的做法
      

  2.   

    while(true)
    {
       //
    }
    如何将结果返给 类A中,线程还要继续,最好给点代码说明
      

  3.   

    楼主去学一下关于委托的知识,给你个简单例子 class Program
         {
             static void Main(string[] args)
             {
                 MainThreadClass mt = new MainThreadClass();
                 mt.Start();
             }
         }     public class MainThreadClass
         {
             string[] arrStr = new string[] { "Microsoft", "IBM", "Oracle" };         public void Start()
             {
                 foreach (string str in arrStr)
                 {
                     SubTreadClass st = new SubTreadClass();
                     st.Completed += new EventHandler(st_Completed);
                     ThreadStart ts = new ThreadStart(st.Method);
                     Thread th = new Thread(ts);
                     th.Name = str;
                     th.Start();
                 }
             }         void st_Completed(object sender, EventArgs e)
             {
                 Console.WriteLine("Thread completed.");
             }
         }     public class SubTreadClass
         {         private event EventHandler m_eventCompleted = null;         public event EventHandler Completed
             {
                 add { m_eventCompleted += value; }
                 remove { m_eventCompleted -= value; }
             }         public void Method()
             {
                 Console.WriteLine(string.Format("Current thread:{0}:{1}", Thread.CurrentThread.Name,
                     "MyClass.Method() executed."));
                 if (m_eventCompleted != null)
                 {
                     m_eventCompleted(this, EventArgs.Empty);
                 }
             }
         }
      

  4.   

    1.在类B里放个全局public变量,类A中访问
    2.在类A里放个全局public数组,类B里线程直接写入数组
      

  5.   

    使用异步委托调用,如果你需要该方法返回的结果,则BeginInvoke的返回值很重要,BgeinInvoke将返回一个IAsyncResult,这可以和委托的EndInvoke配合使用,以在方法调用完毕后检索调用结果