<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Hängender Prozess im Thread-Programm]]></title><description><![CDATA[<p>Hallo zusammen !</p>
<p>Ich habe mit einer NMFTP-Komponente ein kleines FTP-Download-Programm geschrieben, das sämtliche Dateien auf einem Server herunterlädt. Zuerst habe ich es mit einem seriellen Download-Aufruf der einzelnen Dateien probiert, dies hat sich aber als sehr langwierig erwiesen. Jetzt benutze ich für jede Datei einen eigenen Connection-Thread und das funzt eigentlich sehr gut und ist wesentlich schneller. Leider kommt es ab und zu vor, dass das Programm nach dem laden der Dateiliste vom FTP-Server sich einfach aufhängt. Das heisst, dass die einzelnen Threads nicht gestartet werden. Leider kann ich mir darauf keinen Reim machen.</p>
<p>Vielleicht weiß ja jemand von Euch bescheid...</p>
<pre><code>void __fastcall TForm1::FormCreate(TObject *Sender)
{
        strDestPath = ParamStr(1);                    // Zielverzeichnis als Parameter
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormActivate(TObject *Sender)
{
        String Host = &quot;www.xyz.com&quot;;
        String User = &quot;xyz&quot;;
        String Pass = &quot;xyz&quot;;

        if (ParamCount() != 0) {

                Label1-&gt;Caption = &quot;Es werden nun die Online-Bestellungen vom FTP-Server geholt - Bitte warten ... &quot;;

                FTPList = new TStringList();

                NMFTP1-&gt;Host = Host;
                NMFTP1-&gt;UserID = User;
                NMFTP1-&gt;Password = Pass;
                NMFTP1-&gt;Port = 21;
                NMFTP1-&gt;Passive = true;

                try {
                        NMFTP1-&gt;Connect();
                        NMFTP1-&gt;Nlist();
                        NMFTP1-&gt;Disconnect();

                        if (FTPList-&gt;Count == 0) {
                                MessageBox(NULL, &quot;Es sind keine Bestellungen auf dem FTP-Server vorhanden !&quot;, &quot;Meldung&quot;, MB_OK);

                                Close();
                                return;
                        }

                        TThread* thread;

                        for (int iIndex = 0; iIndex &lt; FTPList-&gt;Count; iIndex++) {
                                TNMFTP* NMFTP = new TNMFTP(this);
                                NMFTP-&gt;Host = Host;
                                NMFTP-&gt;UserID = User;
                                NMFTP-&gt;Password = Pass;
                                NMFTP-&gt;Port = 21;
                                NMFTP-&gt;Passive = true;
                                NMFTP-&gt;Connect();
                                NMFTP-&gt;Mode(MODE_BYTE);

                                String strDestination = strDestPath + FTPList-&gt;Strings[iIndex];
                                thread = new DownloadThread(NMFTP, FTPList-&gt;Strings[iIndex], strDestination);
                        }

                        while (thread-&gt;WaitFor() != 1) {}
                }
                catch (...) {
                        MessageBox(NULL, &quot;Es konnte keine Verbindung hergestellt werden !&quot;, &quot;Meldung&quot;, MB_OK);
                }
        }

        Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::NMFTP1ListItem(AnsiString Listing)
{
        FTPList-&gt;Add(Listing);
        iOrderCount++;

        Label2-&gt;Caption = iOrderCount;
        Label2-&gt;Refresh();
}
//---------------------------------------------------------------------------
</code></pre>
<p>Die Thread-Routine sieht folgendermaßen aus:</p>
<pre><code>//---------------------------------------------------------------------------

__fastcall DownloadThread::DownloadThread(TNMFTP* NMFTP, String FileName, String DestPath)
        : TThread(false)
{
        NMFTP1 = NMFTP;
        strFileName = FileName;
        strDestPath = DestPath;

        this-&gt;ReturnValue = 0;
}
//---------------------------------------------------------------------------
void __fastcall DownloadThread::Execute()
{
        NMFTP1-&gt;Download(strFileName, strDestPath);
//        NMFTP1-&gt;Delete(strFileName);
        NMFTP1-&gt;Disconnect();

        this-&gt;ReturnValue = 1;
}
//---------------------------------------------------------------------------
</code></pre>
<p>Best Dank für die Hilfe...</p>
<p>Gruß MacReeg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/80214/hängender-prozess-im-thread-programm</link><generator>RSS for Node</generator><lastBuildDate>Tue, 30 Jun 2026 14:21:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/80214.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Jul 2004 08:01:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hängender Prozess im Thread-Programm on Mon, 19 Jul 2004 08:01:18 GMT]]></title><description><![CDATA[<p>Hallo zusammen !</p>
<p>Ich habe mit einer NMFTP-Komponente ein kleines FTP-Download-Programm geschrieben, das sämtliche Dateien auf einem Server herunterlädt. Zuerst habe ich es mit einem seriellen Download-Aufruf der einzelnen Dateien probiert, dies hat sich aber als sehr langwierig erwiesen. Jetzt benutze ich für jede Datei einen eigenen Connection-Thread und das funzt eigentlich sehr gut und ist wesentlich schneller. Leider kommt es ab und zu vor, dass das Programm nach dem laden der Dateiliste vom FTP-Server sich einfach aufhängt. Das heisst, dass die einzelnen Threads nicht gestartet werden. Leider kann ich mir darauf keinen Reim machen.</p>
<p>Vielleicht weiß ja jemand von Euch bescheid...</p>
<pre><code>void __fastcall TForm1::FormCreate(TObject *Sender)
{
        strDestPath = ParamStr(1);                    // Zielverzeichnis als Parameter
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormActivate(TObject *Sender)
{
        String Host = &quot;www.xyz.com&quot;;
        String User = &quot;xyz&quot;;
        String Pass = &quot;xyz&quot;;

        if (ParamCount() != 0) {

                Label1-&gt;Caption = &quot;Es werden nun die Online-Bestellungen vom FTP-Server geholt - Bitte warten ... &quot;;

                FTPList = new TStringList();

                NMFTP1-&gt;Host = Host;
                NMFTP1-&gt;UserID = User;
                NMFTP1-&gt;Password = Pass;
                NMFTP1-&gt;Port = 21;
                NMFTP1-&gt;Passive = true;

                try {
                        NMFTP1-&gt;Connect();
                        NMFTP1-&gt;Nlist();
                        NMFTP1-&gt;Disconnect();

                        if (FTPList-&gt;Count == 0) {
                                MessageBox(NULL, &quot;Es sind keine Bestellungen auf dem FTP-Server vorhanden !&quot;, &quot;Meldung&quot;, MB_OK);

                                Close();
                                return;
                        }

                        TThread* thread;

                        for (int iIndex = 0; iIndex &lt; FTPList-&gt;Count; iIndex++) {
                                TNMFTP* NMFTP = new TNMFTP(this);
                                NMFTP-&gt;Host = Host;
                                NMFTP-&gt;UserID = User;
                                NMFTP-&gt;Password = Pass;
                                NMFTP-&gt;Port = 21;
                                NMFTP-&gt;Passive = true;
                                NMFTP-&gt;Connect();
                                NMFTP-&gt;Mode(MODE_BYTE);

                                String strDestination = strDestPath + FTPList-&gt;Strings[iIndex];
                                thread = new DownloadThread(NMFTP, FTPList-&gt;Strings[iIndex], strDestination);
                        }

                        while (thread-&gt;WaitFor() != 1) {}
                }
                catch (...) {
                        MessageBox(NULL, &quot;Es konnte keine Verbindung hergestellt werden !&quot;, &quot;Meldung&quot;, MB_OK);
                }
        }

        Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::NMFTP1ListItem(AnsiString Listing)
{
        FTPList-&gt;Add(Listing);
        iOrderCount++;

        Label2-&gt;Caption = iOrderCount;
        Label2-&gt;Refresh();
}
//---------------------------------------------------------------------------
</code></pre>
<p>Die Thread-Routine sieht folgendermaßen aus:</p>
<pre><code>//---------------------------------------------------------------------------

__fastcall DownloadThread::DownloadThread(TNMFTP* NMFTP, String FileName, String DestPath)
        : TThread(false)
{
        NMFTP1 = NMFTP;
        strFileName = FileName;
        strDestPath = DestPath;

        this-&gt;ReturnValue = 0;
}
//---------------------------------------------------------------------------
void __fastcall DownloadThread::Execute()
{
        NMFTP1-&gt;Download(strFileName, strDestPath);
//        NMFTP1-&gt;Delete(strFileName);
        NMFTP1-&gt;Disconnect();

        this-&gt;ReturnValue = 1;
}
//---------------------------------------------------------------------------
</code></pre>
<p>Best Dank für die Hilfe...</p>
<p>Gruß MacReeg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/563506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/563506</guid><dc:creator><![CDATA[MacReeg]]></dc:creator><pubDate>Mon, 19 Jul 2004 08:01:18 GMT</pubDate></item><item><title><![CDATA[Reply to Hängender Prozess im Thread-Programm on Thu, 22 Jul 2004 07:31:25 GMT]]></title><description><![CDATA[<p>Hallo zusammen !</p>
<p>Ich glaube meine Vermutung, dass das Programm deswegen &quot;hängen&quot; bleibt, weil die Connection-Threads gestartet werden obwohl nicht gesichert war, dass die erste Connection zum FTP-Server noch nicht beendet wurden, scheint sich zu bewahrheiten. Nach folgender Code-Ergänzung scheint das Programm nicht mehr mit dem oben genannten Problem behaftet zu sein:</p>
<pre><code>...

                try {
                        NMFTP1-&gt;Connect();
                        NMFTP1-&gt;Nlist();

                        while (NMFTP1-&gt;Connected) {
                                NMFTP1-&gt;Disconnect();
                        }
		...
</code></pre>
<p>Weiterhin habe ich festgestellt, dass das Programm bei einer begrenzten Bandbreite (relativ zum Firmennetzwerk) wie DSL bei mir zuhause, auf 200 heruntergeladene Dateien etwa 3 oder 4 Dateien nicht mit übertragen wurden. Um dies zu Verhindern besteht die Möglichkeit nach dem Download die physikalische Existenz der Datei abzufragen um ggf. den Download zu wiederholen:</p>
<pre><code>void __fastcall DownloadThread::Execute()
{
        if (!FileExists(strDestPath)) {
                NMFTP1-&gt;Download(strFileName, strDestPath);
        }

//        NMFTP1-&gt;Delete(strFileName);
        NMFTP1-&gt;Disconnect();

        this-&gt;ReturnValue = 1;
}
</code></pre>
<p>Für Verbesserungen habe ich natürlich ein offenes Ohr ...</p>
<p>Gruß MacReeg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/565633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565633</guid><dc:creator><![CDATA[MacReeg]]></dc:creator><pubDate>Thu, 22 Jul 2004 07:31:25 GMT</pubDate></item><item><title><![CDATA[Reply to Hängender Prozess im Thread-Programm on Thu, 22 Jul 2004 08:12:41 GMT]]></title><description><![CDATA[<p>Als erste Verbesserung würde ich mich von diesen sch...önen TNM* Kompos distanzieren und eher mit Indy liebäugeln <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/565657</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/565657</guid><dc:creator><![CDATA[Peter]]></dc:creator><pubDate>Thu, 22 Jul 2004 08:12:41 GMT</pubDate></item></channel></rss>