如何在C#中运行顺序线程? [英] How to run sequence thread in c#?

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

问题描述

我有3个线程:

线程1:从DB1获取数据
线程2:从DB2获取数据
线程3:从DB3获取数据

如何编写程序运行方式:
-启动线程1,线程2,线程3
-运行线程1
-完成线程1后,运行线程2
-完成线程2后,运行线程3
-完成线程3之后,再次运行线程1

您能帮我吗???????

I have 3 thread:

Thread 1: get data from DB1
Thread 2: get data from DB2
Thread 3: get data from DB3

How to write my program runs:
- Start Thread 1, Thread 2, Thread 3
- Run Thread 1
- After finishing Thread 1 run Thread 2
- After finishing Thread 2 run Thread 3
- After finishing Thread 3 and run again Thread 1

Can you help me?????

推荐答案

这没有任何意义,因为它违反了线程化的目的.创建一个线程(如果需要的话)并运行该序列.无论如何,您通常需要学习使用线程.从这里开始:
http://msdn.microsoft.com/en-us/library/ms173178%28v = vs.100%29.aspx [ ^ ].

如果您遇到任何问题,请随时提出特定问题.

—SA
It makes no sense, because it defeats the purpose of threading. Create one thread (if you even need it) and run the sequence. Anyway, you need to learn using threads in general. Start here:
http://msdn.microsoft.com/en-us/library/ms173178%28v=vs.100%29.aspx[^].

Please feel free to ask particular question if you face any problems.

—SA


SAKryukov是正确的.仅当您要并行运行某些内容时,才应使用线程.如果它们要一个接一个地运行 ,则不需要线程.
SAKryukov is right. You should use threading only if you want to run something in parallel. If they are going to run one after another, no need of threading.


似乎设计不好,或者您不清楚要做什么.您需要做的只是让线程1从数据库中获取数据.您尚未提供任何需要3个线程才能从3个单独的数据库中获取数据的信息.
Seems like a bad design or you are not clear about what you want to do. All you need to do is have thread one get the data from the database. You have not provided any information that would require 3 threads to get data from 3 separate databases.


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

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