The {APPTYPE CONSOLE} directive has been added, and now my application runs very slowly. Moving the mouse makes it work faster

I am trying to expand a third-party application so that it can be called via the command line in addition to using the graphical interface of the Windows form (preferably mixed mode). This is a fairly simple program that basically downloads the file, and then you press the button and it starts sending UDP network packets.

I need to call an application from another and would like to pass an argument and should be able to return ExitCode to the calling application. From what I read, for this you need to add the {APPTYPE CONSOLE} compiler directive.

I did this, and my application worked the way I wanted it, except that network packets slowed down to bypass. I found that whenever I hover over a form. That the network transfer rate has increased significantly. I suspect that there is some Windows Message Queuing problem, and moving the mouse causes interrupts, which in turn cause message queue processing?

I have googled around and tried calling Application.ProcessMessages and PeekMessages in a timer at 1 ms intervals, and that didn't help at all. I found in this user guide for some other application , it says that Indy 10 is supported both in the APPTYPE CONSOLE types and in the GUI. Honestly, it just bothers me, since I assumed that the entire network library would work in both modes ... but, as I said, I'm not familiar with Delphi.

I am sure that the problem is isolated from a single line in my application, and that is whether or not {APPTYPE CONSOLE} is included.

Does anyone have any idea?

Version Information:
Delphi 7 Personal (Build 4.453)
Indy 9.0.4

+3
5

{APPTYPE CONSOLE} , , , . , , , .

, , . , GUI:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ExitCode := 42;
  Timer1.Interval := 1000;
  Timer1.Enabled := TRUE;
end;

cmd:

@echo off
start /WAIT project1.exe
echo %ERRORLEVEL%

1 , , script 42 .

- GUI- , , . , , , ?

+6

, , . ExitCode, .

ExitCode := 10;

@Echo off
project1
echo %errorlevel%

, 10, .

. API AllocConsole AttachConsole.

, . ( ).

+2

, , :

  • ,
  • GUI

- , (CoreLogic ).

.

:

  • Application.ShowMainForm: = False; MainForm .
  • ExitCode: = 327; (, mghie Gerry ).

:

  • CoreLogic , - , Windows, .
  • Windows, Application.ProcessMessages() CoreLogic
  • , , MainForm , , ( Application.Terminate()). MainForm.OnShow.

, : -)

program VCLAppThatDoesNotShowMainForm;

uses
  Forms,
  MainFormUnit in 'MainFormUnit.pas' {MainForm},
  Windows;

{$R *.res}

procedure CoreLogic;
begin
  Sleep(1000);
  ExitCode := 327;
end;

procedure TestParams;
begin
  if ParamCount > 0 then
  begin
    MessageBox(0, CmdLine, PChar(Application.Title), MB_ICONINFORMATION or MB_OK);
    CoreLogic();
    Application.ShowMainForm := False;
  end;
end;

begin
  Application.Initialize();
  Application.MainFormOnTaskbar := True;
  TestParams();
  Application.CreateForm(TMainForm, MainForm);
  Application.Run();
end.
+1

1 40 (- Windows), . , , , - , .

, , API CreateConsole ( , ), . (!) , .

, . , . ParamCount/ParamStr ExitCode .

0

If some threads in your console application cause synchronization (and I think the Indy stuff actually does), you need to make some preparations:

Assign the method to the WakeMainThread variable . This method must have a TNotifyEvent signature.

Inside this method, CheckSynchronize is called .

See the Delphi help for these two items for more information.

0
source

Source: https://habr.com/ru/post/1713811/


All Articles