使用线程连续运行功能 [英] continuously running function using thread

查看:70
本文介绍了使用线程连续运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

namespace SampleThreading
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {

        public MainWindow ( )
        {
            InitializeComponent ( );
            Thread th = new Thread ( new ThreadStart ( CopyFile ) );
            th.IsBackground = true;
            th.Start ( );
        }

        private void CopyFile ( )
        {

           

        }
    }
}





我想继续运行CopyFile()方法。它无法正常工作



I Want to continuously running the method CopyFile ( ). its not working

推荐答案

请参考此链接:在C#中定期持续运行功能的更好方法


CopyFile 当然是执行一次。如果你需要一个永无止境的处理,那么你必须使用无限循环。
CopyFile is executed once, of course. If you need a never-ending processing there then you have to use an infinite loop.


public MainWindow ( )
        {
            InitializeComponent ( );
            Thread th = new Thread ( ( ) =>
            {
                while ( true )
                {
                    CopyFile ( );
                }
            } );

            th.Start ( );
        }


这篇关于使用线程连续运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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