Page 1 of 1

[SFTP client] NonBlocking mode / console app

Posted: Wed 01 Jun 2016 12:05
by pcz
Hello

I suppose that NonBlocking mode reqire a message loop to work? Am I right?

What is the easiest way to use NonBlocking mode in a windowless application?

Regards
P.C.

Re: [SFTP client] NonBlocking mode / console app

Posted: Fri 03 Jun 2016 12:29
by ViktorV
NonBlocking mode is not supported in console applications. If you want us to implement the feature, please post it at our user voice forum: http://devart.uservoice.com/forums/174370-securebridge If the suggestion gets a lot of votes, we will consider the possibility to implement it.

Re: [SFTP client] NonBlocking mode / console app

Posted: Fri 03 Jun 2016 13:04
by pcz
ViktorV wrote:NonBlocking mode is not supported in console applications. If you want us to implement the feature, please post it at our user voice forum: http://devart.uservoice.com/forums/174370-securebridge If the suggestion gets a lot of votes, we will consider the possibility to implement it.
I just don't have enough time ;)
I have experimented with simple message pumping and it looks to handle it.

If case of anybody interested...

Code: Select all

var
  AppTerminated: Boolean;
  ActiveTransmission: Boolen;

{...}

procedure PumpMessagess;
var
  Unicode: Boolean;
  Msg: TMsg;
begin
  while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
  begin
    Unicode := (Msg.hwnd = 0) or IsWindowUnicode(Msg.hwnd);
    TranslateMessage(Msg);
    if Unicode then
      DispatchMessageW(Msg)
    else
      DispatchMessageA(Msg);
  end;
end;

procedure Wait;
var
  WaitResult: DWORD;
  Dummy: THandle;
begin
  while ActiveTransmission and (not AppTerminated) do
  begin
    // event can be used to avoid potential 1 second delay
    WaitResult := MsgWaitForMultipleObjects(0, Dummy, False, 1000, QS_ALLINPUT);
    if WaitResult = WAIT_OBJECT_0 then   // messages in queue
      PumpMessagess;

    {check termination condition or do anything...}

  end;
end;

{.....}

ScSFTPClientInstance.UploadFile(....);
Wait;

{.....}
It looks that TScSFTPClient class relies mainly on WM_TIMER messages so
- you have to be really careful because some operations (like calling <TScSFTPClient>.OpenFile) can cause deadlock at DispatchMessageA/W call
- disconnect TScSFTPClient when idle to stop WM_TIMER mesages

Re: [SFTP client] NonBlocking mode / console app

Posted: Wed 08 Jun 2016 10:53
by ViktorV
The NonBlocking mode does not work in console applications, since they do not have a native window message handler. If you implement message handling on your own, as you have done, the NonBlocking mode can be used in console applications.