国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

有趣的多線程編程(1)——一個簡單的例子

2024-07-21 02:29:41
字體:
來源:轉載
供稿:網友
//hellowordthread.cs
//------------------------
using system;using system.threading;public class test{    static void main()    {        threadstart job = new threadstart(threadjob);        thread thread = new thread(job);        thread.start();                for (int i=0; i < 5; i++)        {            console.writeline ("main thread: {0}", i);            thread.sleep(1000);        }    }        static void threadjob()    {        for (int i=0; i < 10; i++)        {            console.writeline ("other thread: {0}", i);            thread.sleep(500);        }    }}
結果:
main thread: 0other thread: 0other thread: 1main thread: 1other thread: 2other thread: 3main thread: 2other thread: 4other thread: 5main thread: 3other thread: 6other thread: 7main thread: 4other thread: 8other thread: 9

//usingdelegate.cs
------------------------------------
using system;
using system.threading;

public class test
{
    static void main()
    {
        counter foo = new counter();
        threadstart job = new threadstart(foo.count);
        thread thread = new thread(job);
        thread.start();
       
        for (int i=0; i < 5; i++)
        {
            console.writeline ("main thread: {0}", i);
            thread.sleep(1000);
        }
    }
}

public class counter
{
    public void count()
    {
        for (int i=0; i < 10; i++) { console.writeline ("other thread: {0}", i);
            thread.sleep(500);
        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石河子市| 望谟县| 甘洛县| 兴文县| 龙南县| 松溪县| 满洲里市| 石景山区| 习水县| 石首市| 迁西县| 阳朔县| 吴旗县| 孝感市| 工布江达县| 天柱县| 太白县| 海丰县| 恭城| 盐城市| 南通市| 双牌县| 泰和县| 固原市| 松江区| 凌海市| 岑巩县| 铜川市| 区。| 凌云县| 灯塔市| 介休市| 钦州市| 辛集市| 黔江区| 平泉县| 大荔县| 长汀县| 富宁县| 吉安县| 自治县|