求 C++ Builder 多线程的例子,谢谢(50分)

  • 主题发起人 主题发起人 LikeDFW
  • 开始时间 开始时间
L

LikeDFW

Unregistered / Unconfirmed
GUEST, unregistred user!
求 C++ Builder 多线程的例子,谢谢
 
帮帮我呀
 
分数太少还是 ...
 
帮帮我呀
 
#include <vcl.h>
#pragma hdrstop
#include "Thread.h"
#include "SFmain.h"
#include "card.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall Unit1::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TMyThread::TMyThread(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::Execute()
{
while (!Terminated)
{
Synchronize(MyRead);
}
}
//---------------------------------------------------------------------------
void __fastcall TMyThread::MyRead()
{
get = genReadCard(TollMain->hComDev,20,0,8,TollMain->carddata);
//读卡代码
if (get==0)
{
TollMain->IC_Number = TollMain->carddata;
TollMain->IC_Number = TollMain->IC_Number.SubString(1,8);
TollMain->Edit1->Text = TollMain->IC_Number;
TollMain->ListBox1->Items->Add(TollMain->IC_Number);
}
Sleep(20);
}
调用:
IC_Thread = new TMyThread(false);//非接触式IC卡
关闭:
IC_Thread->Terminate();
//非接触式IC卡
 
在这里有BCB自带的例子,用TThread做关键词在Examples中搜索还有很多:
/CBuilder5/Examples/Apps/Thread,好像是一个多线程排序的例子
 
后退
顶部