Éric Fleming Bonilha wrote:
> But the main thread should not be blocked right?

Correct, there must be something else blocking.

You can try a simple test application (V6).
Create a new VCL forms application and drop a TButton and a
TLabel onto the form. Paste the code below into the editor
and assign the OnClick event.

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

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OverbyteIcsWndControl, OverbyteIcsWSocket,
  StdCtrls;

type
  TMyThread = class(TThread)
  private
    procedure WSocket1DnsLookupDone(Sender: TObject; ErrCode: Word);
  protected
    procedure Execute; override;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    procedure WmUser(var Msg: TMessage); message WM_USER;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyThread }

procedure TMyThread.WSocket1DnsLookupDone(Sender: TObject; ErrCode: Word);
begin
    PostMessage(TWSocket(Sender).Handle, WM_QUIT, 0, 0);
    PostMessage(Form1.Handle, WM_USER, 0, 0);
end;

procedure TMyThread.Execute;
var
    WSocket1 : TWSocket;
begin
    WSocket1 := TWSocket.Create(nil);
    try
        WSocket1.OnDnsLookupDone := WSocket1DnsLookupDone;
        WSocket1.DnsLookup('foo');
        WSocket1.MessageLoop;
    finally
        WSocket1.Free
    end;
end;


var
    Cnt: Integer;

procedure TForm1.WmUser(var Msg: TMessage);
begin
    Inc(Cnt);
    Label1.Caption := IntToStr(Cnt);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
    I : Integer;
begin
    Cnt := 0;
    Label1.Caption := '0';
    for I := 1 to 10 do
    begin
        with TMyThread.Create(FALSE) do
        begin
            FreeOnTerminate := TRUE;
            Sleep(0);
        end;
    end;
end;

end.

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

Reply via email to