Autor Beitrag
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 19.02.06 13:41 
Morgen!

Hab gerade eines meiner Programme multithreading-fähig gemacht - funktioniert auch alles super. Einzig MessageDlg macht mir Probleme. Das Problem ist schwer beschreibbar, daher hab ich die EXE angehängt. Reproduzierbar durch folgendes: eine oder mehrere Dateien kopieren und nachdem das geschehen ist, das selbe nochmal. Kopiert man mehrere Dateien, wird der MessageDlg, der "Destination file already exists. Replace?" fragt, immer "größer" (schwer zu beschreiben wie gesagt), bis man nichtmal mehr das Fenster schließen kann. Jemand eine Idee, woran das liegen könnte?

AXMD
Einloggen, um Attachments anzusehen!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 19.02.06 14:05 
Die VCL ist nicht Thread-Sicher *g* ;-) Erklärt das dein Problem?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
AXMD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 19.02.06 14:51 
Das erklärt das Problem, löst es aber nicht -_-

AXMD
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: So 19.02.06 16:19 
Lösung MessageBox-API verwenden oder aber MesssageDlg-Aufrufe synchronisieren (im primären Thread aufrufen). Möglichkeiten der Synchronisierung: TThread.Synchronize() oder per SendMessage eine Message an die MainForm welche dann die entsprechende Aktion ausführt.

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
AXMD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 19.02.06 16:26 
user profile iconMotzi hat folgendes geschrieben:
MesssageDlg-Aufrufe synchronisieren (im primären Thread aufrufen)


Hört sich gut an. Wie kann am besten anstellen? Das Problem ist nämlich, dass ich zwei oder drei lokale Variablen des Threads dazu setzen muss...

AXMD
AXMD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 19.02.06 19:12 
Für alle, die die Lösung interessiert:

MessageDlg in einer Methode des Threads deklarieren...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TFileCopierThread.MsgDlg;
begin
  FMsgDlgResult := MessageDlg('Destination file already exists. Replace? ', mtConfirmation, [mbYes, mbNo, mbYesToAll, mbNoToAll], 0);
end;


... und dann (wie Motzi richtig gesagt hat) per Synchronize aufrufen - eben dort, wo man's braucht (ich hatte Probleme damit, weil die zu "synchronisierende" Methode keine Parameter haben darf! Das mit den Parametern ist aber über Variablen (private oder protected) lösbar, ebenso das Result):

ausblenden Delphi-Quelltext
1:
Synchronize(MsgDlg);					


AXMD

PS.: Vielen Dank nochmal an user profile iconChristian S. ;)