Article View: borland.public.cppbuilder.nativeapi
Article #15835Re: Thread synchronize
From: Tharun Pillay
Date: Mon, 09 Jun 2003 06:37
Date: Mon, 09 Jun 2003 06:37
105 lines
3793 bytes
3793 bytes
Aaahh. Very clever.
I eventually got a bit desperate and did the following in the worker thread:
//8<-------------------------------------------------
TClientSocket *csToServer = new TClientSocket (NULL);
TcsToServer_Data *csdToServer = new TcsToServer_Data;
Application->ProcessMessages ();
csToServer->Port = xxx
csToServer->Address = xxx.xxx.xxx.xxx
csToServer->Data = cs
// set up event procs
csToServer->Active = true;
do
{
Sleep(10);
Application->ProcessMessages();
} while ((!csToServer->Active) && (!csd->Error));
// continue processing......
csToServer->Close();
Application->ProcessMessages();
delete csdToServer;
delete csToServer;
//8<-------------------------------------------------
Is there anything wrong with this code - it doesn't seem to cause any
errors.
Thanks,
Tharun
"Remy Lebeau (TeamB)" <gambit47@yahoo.com> wrote in message
news:3ee39d3f$1@newsgroups.borland.com...
>
> "Tharun Pillay" <tharun@webmail.co.za> wrote in message
> news:3ee3378b@newsgroups.borland.com...
>
> > Does anyone know how to implement the VCL
> > TThread->Synchronize using APIs?
> > My problem is I need to call a function in the
> > VCL thread to create a TClientSocket and send it
> > back to my worker thread somehow.
>
> Up to and including BCB5, Synchronize() is implementated using
SendMessage()
> to send a custom message to the main VCL thread, where the lParam of the
> message is a pointer to the thread that is calling Synchronize(). You
could
> do something similar to let the main VCL thread return a pointer back to
> your thread, ie:
>
> typedef struct
> {
> TMyThread *thread;
> TClientSocket *socket;
> } TMyStruct;
>
> #define APPWM_MYMESSAGE (WM_APP + 100)
>
> ...
>
> void __fastcall TMyThread::Execute()
> {
> ...
> TMyStruct s;
> s.thread = this;
> s.socket = NULL;
> if( SendMessage(Application->MainForm->Handle, APPWM_MYMESSAGE, 0,
> (LPARAM)&s) )
> {
> // use s.socket as needed
> delete s.socket;
> }
> ...
> }
>
> ...
>
> void __fastcall TMainForm::WndProc(TMessage &Message)
> {
> if( Message.Msg == APPWM_MYMESSAGE )
> {
> try
> {
> ((TMyStruct*)Message.LParam)->socket = new
> TClientSocket(NULL);
> Message.Result = TRUE;
> }
> catch(Exception&) {
> Message.Result = TRUE;
> }
> }
> else
> TForm::WndProc(Message);
> }
>
>
> Gambit
>
>
Technical Details
Message-ID:
<3ee42a38@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ee3378b@newsgroups.borland.com> <3ee39d3f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,82b0c0f74a86ff1b X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-08 23:36:22 PST From: "Tharun Pillay" <tharun@webmail.co.za> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ee3378b@newsgroups.borland.com> <3ee39d3f$1@newsgroups.borland.com> Subject: Re: Thread synchronize Date: Mon, 9 Jun 2003 08:37:03 +0200 Lines: 107 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 196.15.202.200 Message-ID: <3ee42a38@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1055140408 196.15.202.200 (8 Jun 2003 23:33:28 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-01!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail