🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #21

Multi-threading...

#21
From: Carl Danley
Date: Sun, 20 Jul 2008 05:38
71 lines
3921 bytes
Alright so... I am running into a problem that is holding me back from 
writing the rest of my application. I have tried to find information on this 
error but it seems that I cannnot. Im making something like this:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
HANDLE ThreadA, ThreadB;
//---------------------------------------------------------------------------
DWORD WINAPI Thread1(LPVOID Param);
DWORD WINAPI Thread2(LPVOID Param);
//---------------------------------------------------------------------------
DWORD WINAPI Thread2(LPVOID Param)
{
 //code here
 ShowMessage("test2");
 //terminate Thread
 TerminateThread(Thread, false);
 return 0;
}
//---------------------------------------------------------------------------
DWORD WINAPI Thread1(LPVOID Param)
{
 //code here
 ShowMessage("test");
 //terminatethread
 TerminateThread(Thread, false);
 return 0;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
 : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 //initialize the thread
 DWORD Id;
 Thread = CreateThread(0, 0, ThreadA, Form1->Handle, CREATE_SUSPENDED, &Id);
 ResumeThread(Thread);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
 //initialize the thread
 DWORD Id;
 Thread = CreateThread(0, 0, ThreadB, Form1->Handle, CREATE_SUSPENDED, &Id);
 ResumeThread(Thread);
}
//---------------------------------------------------------------------------

For example, all of my FTP work would be done in Thread1 and the Algorithm 
to deal with the files downloaded and populate a component that shows the 
users info on the latest applications would be done in Thread2. Here is my 
problem: When I actually add the full implementation into these threads, 
they crash the program on exit. What am I doing wrong? Is there some site 
for BCB that can help me? I just need to see an example of how a fully 
thread, working application works... The compiler error I get is Error 1400: 
Invalid Window Handle... I have had other people test this and yet it doesnt 
work on their end either... I have been pulling my hair for about a week... 
Any help would be greatly appreciated, as i'm trying to push this 
application out as an Alpha version in the next 2 weeks... 
Technical Details
Message-ID: <4882cf55$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b069f0aa9205a142,start
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Carl Danley" <cdanley@codebyter.com>
From: "Carl Danley" <cdanley@codebyter.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Multi-threading...
Date: Sun, 20 Jul 2008 01:38:31 -0400
Lines: 72
Organization: CodeByter Software
MIME-Version: 1.0
Content-Type: text/plain;
 format=flowed;
 charset="iso-8859-1";
 reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Windows Mail 6.0.6000.16480
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16545
NNTP-Posting-Host: 76.18.43.186
Message-ID: <4882cf55$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1216532309 76.18.43.186 (19 Jul 2008 22:38:29 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 3757