Re: [twsocket] Using Pop3Cli in a thread

2006-08-17 Thread Wilfried Mestdagh
Hello Patrick,

No using TSyncPop3Cli is discouraged.

I cannot check at moment. But the component has a data socket, FSocket
probably or similar. You can use the messageloop from this one if you
sete on this TWSocket MultiThread to true.

---
Rgds, Wilfried [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html
http://www.mestdagh.biz

Thursday, August 17, 2006, 02:44, Patrick Wong wrote:

 Thank you for your response.

 Or use the messageLoop of TWSocket if you dont need to receive custom
 messages. Set Multithreaded to true.

 But may I know how?  I am not quite familiar with Delphi.  From the
 Pop3prot.hpp MultiThreaded is a protected bool of TSyncPop3Cli, which
 is inherited from TPop3Cli.  Should I use TSyncPop3Cli instead?

From Arno's previous message,

 1 - Create the Pop3Cli instance in Execute 
 2 - Assign properties and events
 3 - Connect 
 4 - Start your MessageLoop

 It would be great if a sample code excerpt that you can kindly show
 me.  Should the worker thread call connect once, and other functions
 in every mail retrieval cycle?  My thought was to connect - get mails
 - delete mails -quit in every cycle.

 Many thanks.

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Using Pop3Cli in a thread

2006-08-17 Thread Arno Garrels
Patrick Wong wrote:
 Thank you for your response.
 
 Or use the messageLoop of TWSocket if you dont need to receive custom
 messages. Set Multithreaded to true.
 
 But may I know how?  I am not quite familiar with Delphi. 

Writing/using message loops is not specific to Delphi but to Windows 
applications. 
Wilfried ment that you may use method Pop3Cli.CtrlSocket.Messageloop instead of
writing your own message pump.

 From the
 Pop3prot.hpp MultiThreaded is a protected bool of TSyncPop3Cli
, which
 is inherited from TPop3Cli.  Should I use TSyncPop3Cli instead? 

No, better run async even in a worker thread.
 
 
 From Arno's previous message,
 
 1 - Create the Pop3Cli instance in Execute
 2 - Assign properties and events
 3 - Connect
 4 - Start your MessageLoop
 
 It would be great if a sample code excerpt that you can kindly show
 me.  Should the worker thread call connect once, and other functions
 in every mail retrieval cycle?  My thought was to connect - get
 mails - delete mails -quit in every cycle.   

There's no difference between running the component in main thread
or in a worker thread given you process messages by some kind of
message loop. 

Delphi's class TThread does not implement such a message loop by
default .

Think asynchrone, call Connect and the take any further action in the
various event handlers.

---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html

 
 
 
 --
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://www.elists.org/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Re: [twsocket] Using Pop3Cli in a thread

2006-08-17 Thread DZ-Jay

On Aug 17, 2006, at 03:29, Arno Garrels wrote:

 There's no difference between running the component in main thread
 or in a worker thread given you process messages by some kind of
 message loop.

 Delphi's class TThread does not implement such a message loop by
 default .

 Think asynchrone, call Connect and the take any further action in the
 various event handlers.

And to answer your second question:  you should call connect, then 
retrieve mail and quit, on every cycle.  There is no need to leave the 
connection open indefinitely, and in fact the server may just close it 
after a time out period.  Doing this asynchroneously means using a 
state-machine, and OnRequestDone() event to trigger the next method in 
your chain.  In your case, each cycle you will need to do:

- Connect
- USER/PASS (to log in)
- UIDL (to get message list)
- RETR/DELE (for each message, to retrieve and delete it)
- QUIT

dZ.

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Using Pop3Cli in a thread

2006-08-15 Thread Arno Garrels
I'm not sure what you try to do, but it's easy:

1 - Create the Pop3Cli instance in Execute 
2 - Assign properties and events
3 - Connect 
4 - Start your MessageLoop

---
Arno Garrels [TeamICS]
http://www.overbyte.be/eng/overbyte/teamics.html


Patrick Wong wrote:
 Dear all,
 
 I am using BCB6 and ICS.  I reference The MailRcv application as a
 start of my new task.  It works fine as long as the Pop3Cli is
 created and used in the main GUI context.  For my app I need to do
 the POP3 mail client as a worker thread.  However it does not work as
 the event Pop3ClientRequestDone can never be triggered.  The symptom
 is that after calling Connect(), a call to User() throws exception as
 it is in pop3DnsLookupState.  
 
 I suspect that this is caused by the lack of a message queue in the
 worker thread. 
 
 As such I try to create a message loop using the ConApp.pas as an
 example: 
 
 void __fastcall TMailClientThread::MessageLoop(void)
 {
   TMsg *pMsg;
 
   while(!Terminated  GetMessage(pMsg, 0, 0, 0))
   {
  TranslateMessage(pMsg);
  DispatchMessage(pMsg);
   }
 }
 
 void __fastcall TMailClientThread::Execute()
 {
   this-MessageLoop();
 
   // Place thread code here 
   while(!Terminated)
   {
  :
  :
   }
 }
 
 However the thread execution will not proceed as the TranslateMessage
 and DispatchMessage will not be reached in the while() within the
 MessageLoop function call.  
 
 Is there any ICS sample that instructs how to implement a message
 queue in a threaded application? 
 
 If I am wrong in the above understanding please kindly advise.  I
 will be happy if there is indeed a simpler solution. 
 
 Thanks in advance.
 
 
 
 
 --
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://www.elists.org/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be