如何在一个进程中同时运行2个线程? [英] How to run 2 threads simultaneously within a process?

查看:94
本文介绍了如何在一个进程中同时运行2个线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请告诉我如何在一个进程中同时运行2个线程.


在此先感谢

Hi There,

Please tell me how to run 2 threads simultaneously within a process.


Thanks in advance

推荐答案

如果您想学习多线程,
http://msdn.microsoft.com/en-us/library/aa645740 (v = vs.71).aspx [ http://www.fincher.org/tips/Languages/csharpThreads.shtml [ ^ ]

使用 google [
If you want to learn multithreading,
http://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx[^]
http://www.fincher.org/tips/Languages/csharpThreads.shtml[^]

Use google[^] for more tutorials.


通常有以下三种方式:

There are generally three ways:


  1. System.Threading.Thread(请参阅其构造函数和方法Run);请参阅 http://msdn.microsoft.com/en-us/library/system.threading .thread.aspx [ ^ ];
  2. 使用线程池中的线程,请参阅 http://msdn.microsoft.com/en-us/library/system.componentmodel .backgroundworker.aspx [ ^ ].

  1. System.Threading.Thread (see its constructor and the method Run); see http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx[^];
  2. Using thread from the thread pool, see http://msdn.microsoft.com/en-us/library/3dasc8as(v=VS.100).aspx[^];
  3. Using System.ComponentModel.BackgroundWorker; see http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^].



在这三种情况下,您都是在单独的线程中运行代码的.无论线程如何获得,它们都是等效的线程.您可以使用System.Threading.Thread.CurrentThread以及类System.Threading.Thread的其他属性和方法.

-SA



In all three cases you run your code in a separate thread; no matter how the thread is obtained, they are all just equivalent threads; you can use System.Threading.Thread.CurrentThread and other properties and methods of the class System.Threading.Thread.

—SA


使用线程 [^ ]类.您可以在此处 [
Use Thread[^] class. You can find more about using threads here[^]


这篇关于如何在一个进程中同时运行2个线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆