⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threadstate.cpp

📁 Visual_C++[1].NET_Bible1 Visual_C++宝典书中的全部源码
💻 CPP
字号:
// This is the main project file for VC++ application project 
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

using namespace System;
using namespace System::Threading;

__gc class CTicketDispenser
{
public:
  static int iNextTicket = 1;
public:
  __property int get_NextTicket()
  {
    return iNextTicket++;
  }
};

__gc class CWorkerThread
{
public:
  CWorkerThread(int iThreadId) 
    : m_iThreadId(iThreadId)
  {
    m_pThread = new Thread(new ThreadStart(this, &CWorkerThread::ThreadMethod));
  }

protected:
  int m_iThreadId;

protected:
  Thread* m_pThread;
public:
  void Start()
  {
    if (m_pThread)
    {
      m_pThread->Start();
    }
  }

  void ThreadMethod()
  {
    CTicketDispenser* pTicket = new CTicketDispenser();
    Console::WriteLine("[CWorkerThread::ThreadMethod] ID {0} gets ticket {1}", 
      __box(m_iThreadId),
      __box(pTicket->NextTicket));
  }
};

// This is the entry point for this application
int _tmain(void)
{
  for (int i = 1; i < 6; i++)
  {
    Console::WriteLine("[_tmain] Starting thread {0}", __box(i));
    CWorkerThread* pThread = new CWorkerThread(i);
    pThread->Start();
  }

  Console::ReadLine();
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -