Hi All
I have a huge problem for me. Im trying to make an application wich is tftp server. I wnat it to recive files from clients in first thread and making some operations in other thread. I have one thread wich works fine, geting and storing files. Secound one is looking for new files in storing path - opening they and printing (by AProcess.CommandLine) and thats fine. But - there is a problem bc id like to deleting files after done operations co im using AProcess.Options+[poWaitOnExit] to be sure operations are done. In the same time (when i making operations on stored files) i cant recevie new files. It looks like one thread blocking the secound one. How its possible? What i should to do to get that threads working thogether but not waiting. Im stick a pice of my code:
in form.create (main unit - Unit1)
TFTPD := TTFTPDaemonThread.Create('0.0.0.0',EditPort.Text);
PrintThread := TPrintThread.Create(MainForm.PathEdit.Text,MainForm.EditPathGost.Text,MainForm.EditLPR.Text,MainForm.EditPathAcrobat.Text,MainForm.ComboBoxPrinter.Text,MainForm.EditPathBrowser.Text,MainForm.EditOff.Text,MainForm.CheckBoxPrev.Checked); // This way it doesn't start automatically
TTFTPDaemonThread is standard demo
and my secound thread:
while not Terminated do
begin
FindFirst(Fpath+'*.*',AnyFile,Dir);
while (DosError=0) do
begin
if (Dir.Name<>'.') and (Dir.Name<>'..') then
begin
fStatusText:=Fpath+Dir.Name;
Synchronize(@Showstatus);
{$ifdef Unix}
PrintIt(Fpath+Dir.Name,Fghost,Flpr,Fprinter);
{$endif}
{$ifdef Windows}
PrintIt(Fpath+Dir.Name,Fghost,Facrobat,Fprinter);
{$endif}
if Fprev=true then
Preview(Fpath+Dir.Name,Fbrowser,Facrobat,Foffice);
try
begin
fStatusText:='Kasowanie pliku wejściowego: ' + Fpath+Dir.Name;
DeleteFile(Fpath+Dir.Name);
Synchronize(@ShowStatus);
end;
except
begin
FLogMessage:='Błąd podczas kasowania pliku wejściowego: ' + Fpath+Dir.Name;
Synchronize(@ShowStatus);
end;
end;
try
begin
FLogMessage:='Kasowanie pliku wyjściowego: ' + Fpath+Dir.Name + OutputName(Dir.Name);
DeleteFile(Fpath+Dir.Name + OutputName(Dir.Name));
Synchronize(@ShowStatus);
end;
except
begin
FLogMessage:='Błąd podczas kasowania pliku wyjściowego: ' + Fpath+Dir.Name + OutputName(Dir.Name);
Synchronize(@ShowStatus);
end;
end;
end;
FindNext(Dir);
end;
FindClose(Dir);
sleep(2000);
end;
And procedures in that:
Procedure InBrowser(filename,przegladarka:string);
var
AProcess: TProcess;
begin
AProcess := TProcess.Create(nil);
AProcess.CommandLine := przegladarka+ ' ' + filename;
AProcess.Options := AProcess.Options + [poWaitOnExit];
AProcess.Execute;
AProcess.Free;
end;
Procedure PrintIt(filename,imagemagic,acrobat,drukarka: string);
var
AProcess1: TProcess;
AProcessPrint: TProcess;
extension:string;
czyPrint:boolean;
begin
AProcess1 := TProcess.Create(nil);
extension:=GetExtension(filename);
czyPrint:=true;
if extension='.jpg' then AProcess1.CommandLine := imagemagic+ ' ' + filename + ' ' + OutputName(filename)
else if extension='.gif' then AProcess1.CommandLine := imagemagic+ ' ' + filename + ' ' + OutputName(filename)
else if extension='.png' then AProcess1.CommandLine := imagemagic+ ' ' + filename + ' ' + OutputName(filename)
else if extension='.htm' then AProcess1.CommandLine := imagemagic+ ' ' + filename + ' ' + OutputName(filename)
else if extension='.html' then AProcess1.CommandLine := imagemagic+ ' ' + filename + ' ' + OutputName(filename)
else if extension='.pdf' then RenameFile(filename, OutputName(filename))
else czyPrint:=false;
AProcess1.Options := AProcess1.Options + [poWaitOnExit];
if (not (extension='.pdf')) and (czyPrint=true) then
begin
AProcess1.Execute;
AProcess1.Free;
AProcessPrint := TProcess.Create(nil);
end;
if czyPrint then
{$ifdef Unix}
AProcessPrint.CommandLine := acrobat+ ' -P ' + drukarka + ' ' + OutputName(filename);
{$endif}
{$ifdef Windows}
AProcessPrint.CommandLine := acrobat+ ' /t ' +OutputName(filename)+' "'+drukarka+'"';
{$endif}
AProcessPrint.Options := AProcessPrint.Options + [poWaitOnExit];
AProcessPrint.Execute;
AProcessPrint.Free;
end;
Procedure Preview(filename,IntBrowser,Acrobat,Office: string);
var
extension:string;
begin
extension:=GetExtension(filename);
if extension='.jpg' then InBrowser(filename, IntBrowser)
else if extension='.gif' then InBrowser(filename, IntBrowser)
else if extension='.png' then InBrowser(filename, IntBrowser)
else if extension='.htm' then InBrowser(filename, IntBrowser)
else if extension='.html' then InBrowser(filename, IntBrowser)
else if extension='.pdf' then InBrowser(filename, Acrobat)
else if extension='.doc' then InBrowser(filename, Office)
else if extension='.docx' then InBrowser(filename, Office)
else if extension='.xls' then InBrowser(filename, Office)
else if extension='.xlsx' then InBrowser(filename, Office)
else if extension='.odt' then InBrowser(filename, Office)
else if extension='.odf' then InBrowser(filename, Office)
else if extension='.sxw' then InBrowser(filename, Office)
else
begin
try
InBrowser(filename, Office);
except;
end;
end;
end;
Can u help me in that? What im doing wrong?
btw sorry for my english