| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 243 人关注过本帖
标题:线程问题
收藏  订阅  推荐  打印
xjxxdnmwj
Rank: 2
等级:注册会员
帖子:49
积分:640
注册:2008-5-12
线程问题

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace wenjian
{
    class Program
    {
        static void Main(string[] args)
        {

            

            Thread.CurrentThread.Name = "1";
            Thread x = new Thread(new ThreadStart(ac));
            x.Name = "fd";
            Thread u = new Thread(new ThreadStart(ff));
            u.Name="ff";
            x.Start();
            u.Start();
            u.Priority = ThreadPriority.Highest;
            


        }
        static void ac()
        {
           
                for (int i = 0; i < 5; i++)
                {
                    Console.WriteLine("re");
                }
            
        
        }
        static void ff()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(i);
            }

        }
    }
}
为什么他还是先运行前面的.
我设置了应该是运行后面的 啊

[ 本帖最后由 xjxxdnmwj 于 2008-8-4 22:20 编辑 ]
附件: 只有本站会员才能下载或查看附件,请您 登录注册
2008-8-4 22:18
vfdff
Rank: 6Rank: 6
等级:金牌会员
威望:4
帖子:1169
积分:13014
注册:2005-7-15
回复 1# xjxxdnmwj 的帖子

你哪里设置的 ??没有看出来
2008-8-4 23:58
fetso
Rank: 1
等级:新手上路
帖子:14
积分:242
注册:2008-4-12
回复 2# vfdff 的帖子

u.Priority = ThreadPriority.Highest;
2008-8-5 03:15
fetso
Rank: 1
等级:新手上路
帖子:14
积分:242
注册:2008-4-12
回复 1# xjxxdnmwj 的帖子

应该是电脑环境的问题,我的运行是和你预想中的一样的,不会出现你所贴出来的结果。而是0 1 2 3 4 re re re re re
2008-8-5 03:17
meihonganddulon
Rank: 1
来自:河南郑州
等级:新手上路
帖子:20
积分:320
注册:2008-7-18
回复 1# xjxxdnmwj 的帖子

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;
namespace wenjian
{
    class Program
    {
        static void Main(string[] args)
        {


            try
            {
                Thread.CurrentThread.Name = "1";
                Thread x = new Thread(new ThreadStart(ac));
                x.Name = "fd";
                Thread u = new Thread(new ThreadStart(ff));
                u.Name = "ff";
                u.Priority = ThreadPriority.AboveNormal;
                x.Start();
                u.Start();
               
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());   
            }



        }
        static void ac()
        {

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("re");
            }


        }
        static void ff()
        {
            for (int i = 0; i < 1000; i++)
            {
                Console.WriteLine(i);
            }

        }
    }
}
2008-8-5 09:02
共有 242 人关注过本帖
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.054618 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved