AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Restarting Main Application in TThread Class
Thema durchsuchen
Ansicht
Themen-Optionen

Restarting Main Application in TThread Class

Ein Thema von FaNIX · begonnen am 1. Feb 2008 · letzter Beitrag vom 7. Feb 2008
 
alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#7

Re: Restarting Main Application in TThread Class

  Alt 7. Feb 2008, 22:24
Hi there.

Send a message from the thread to the main app. Let the thread die or not, this is up to you. The only thing what you should to is to let the main app know wether the thread is dead or not. This could be done by setting the 'FreeOnTerminate' property to false.

Ok, here are my ideas:


Delphi-Quellcode:
Procedure TMyThread.Execute;
Begin
  While Not Terminated Do Begin
     .... // Most likely you would have something like 'WaitForSingleObject' here to preserve CPU cycles.
     If MainAppMustRestart Then Begin
        PostMessage(MainForm.Handle, WM_RESTARTAPPLICATION,0,0);
        Terminate; // If you want
     End
  End
End;
....
Type
  TMainForm = Class (TForm)
  ...
    Procedure wmRestart (War Msg : TMessage); Message WM_RESTARTAPPLICATION;
  End;
...
Procedure TMainForm.wmRestar (Var Msg : TMessage);
Begin
  With MyThread Do Begin
    Terminate;
    WaitFor;
    Free;
  End;
  Application.Terminate;
  Close;
End;
Should'nt cause much problems.

In case you have troubles with threads, consider downloading my workerthread pool and define a 'kill application job', which essentially does the message sending.
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:48 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz