从两个不同的线程调用两个不同的方法 [英] Calling two different methods from two different thread

查看:100
本文介绍了从两个不同的线程调用两个不同的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我有一个问题,如下所示。



我有tow方法说BindCSVData()和BindTreeViewData()



1st我想在执行一段时间之后调用BindCSVData()我想要开始执行BindTreeViewData()。那我怎么能这样做呢?



我的代码如下。

线程thStart = new Thread( BindCSVData);

thStart.IsBackground = true;

thStart.Start();



线程thStart1 =新线程(BindTreeViewData);

thStart1.Start();



我的场景是First BindCSVData在特定时间后获取调用Interval BindTreeViewData将接到电话,然后两者同时执行。



我的代码中有什么要改变吗?

请帮帮我。



谢谢,

Rajan

Hi Guys.

I have a question and that is as below.

I Have tow Methods Say "BindCSVData()" and "BindTreeViewData()"

1st I want to call "BindCSVData()" after some time of execution of that I want to start execute "BindTreeViewData()". So how can I do that ?

My Code is as below.
Thread thStart = new Thread(BindCSVData);
thStart.IsBackground = true;
thStart.Start();

Thread thStart1 = new Thread(BindTreeViewData);
thStart1.Start();

My scenario is that First BindCSVData get Call after a specific time Interval BindTreeViewData will get call and then both get execute simultaneously.

Is anything to change in My code ?
Please help me Out.

Thanks,
Rajan

推荐答案

使用Timer并在其tick事件中或已经过去的事件,开始第二个线程。
use a Timer and in its tick event or elapsed event, start the second thread.


在那边添加这一行....

Add this line over there ....
while (!thStart.IsAlive) ;



这将确保您的第一个线程开始工作......


This will make sure that your first thread is started working...

  Thread thStart = new Thread(BindCSVData);
  thStart.IsBackground = true;
  thStart.Start();
  while (!thStart.IsAlive) ;
  Thread thStart1 = new Thread(BindTreeViewData);
  thStart1.Start();


这篇关于从两个不同的线程调用两个不同的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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