The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.
One of a set of tools we're offering as a way of saying thank you for being a part of the community.
You can use a thread counter, and wait for the thread limit to be less that a specified max limit before spawing a new thread. Example based off the code I gve you.
Russell
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TFormMailSender = class(TForm)
...
end;
type
TThreadSender = class(TThread)
private
// Private declarations
FForm: TFormMailSender;
FMailSend: TStringList;
FIDHTTP: TIdHTTP;
FMailRecv: String;
FRelayURL: String;
FMail: String;
protected
// Protected declarations
procedure AfterSend;
procedure BeforeSend;
procedure Execute; override;
public
// Public declarations
constructor Create(Form: TFormMailSender; Mail: String);
end;
const
MaxThreads = 5;
var
FormMailSender: TFormMailSender;
ThreadCounter: Integer = 0;
implementation
{$R *.DFM}
procedure TThreadSender.BeforeSend;
begin
// Get relay url
FRelayURL:=FForm.EditSmtpR
// Get post parameters
FMailSend.Values['email']:
FMailSend.Values['html']:=
FMailSend.Values['subject'
FMailSend.Values['from']:=
FMailSend.Values['fromname
end;
procedure TThreadSender.AfterSend;
begin
// Call in the main thread
FForm.Memo1.Text:=FMailRec
end;
procedure TThreadSender.Execute;
begin
// Create http component for mailing
FIDHTTP:=TIdHTTP.Create(nil);
// Resource protection
try
// Create string list for sending
FMailSend:=TStringList.Cre
// Resource protection
try
// Get post parameters
Synchronize(BeforeSend);
// Perform the post
FMailRecv:=FIDHTTP.Post(FR
// Set results
Synchronize(AfterSend);
finally
// Free string list
FMailSend.Free;
end;
finally
// Free component
FIDHTTP.Free;
// Drop the thread counter
InterlockedDecrement(Threa
end;
end;
constructor TThreadSender.Create(Form:
begin
// Increase the thread counter
InterlockedIncrement(Threa
// Set parameters
FForm:=Form;
FMail:=Mail;
SetLength(FRelayURL, 0);
// Perform inherited (don't suspend)
inherited Create(False);
// Set thread props
FreeOnTerminate:=True;
Priority:=tpLower;
end;
procedure TFormMailSender.Button1Cli
var count: Integer;
dwThreads: Integer;
Mail: String;
begin
Count:=0;
while (Count < MemoList.Lines.Count) do
begin
while True do
begin
try
InterlockedIncrement(Threa
finally
dwThreads:=InterlockedDecr
end;
if (dwThreads < MaxThreads) then
break
else
Application.ProcessMessage
end;
Mail:=MemoList.Lines.Strin
TThreadSender.Create(Self,
Inc(Count);
end;
end;
end.