Delphi TThread.CurrentThread和EAccessViolation - 这是一个Bug还是我的无能力? [英] Delphi TThread.CurrentThread and EAccessViolation - Is This a Bug or My Incompetence..?

查看:514
本文介绍了Delphi TThread.CurrentThread和EAccessViolation - 这是一个Bug还是我的无能力?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi 2009中,我发现任何时候在应用程序中使用TThread.CurrentThread,当应用程序关闭时,我会收到以下错误消息:

In Delphi 2009 I'm finding that any time I use TThread.CurrentThread in an application, I'll get an error message like the following when the application closes:

Exception EAccessViolation in module ntdll.dll at 0003DBBA.
Access violation at address 7799DBBA in module 'ntdll.dll'.  Write of
address 00000014.

除非它只是我的机器,你可以在一个几秒钟:创建一个新的Delphi Forms应用程序,在窗体中添加一个按钮,并使用如下按钮的事件处理程序:

Unless it's just my machine, you can replicate this in a few seconds: create a new Delphi Forms Application, add a button to the form, and use something like the following for the button's event handler:

procedure TForm1.Button1Click(Sender: TObject);
begin
  TThread.CurrentThread;
end;

在我的Vista机器和XP机器上,我发现,如果我't 点击按钮一切都很好,但如果我执行单击按钮,当我关闭应用程序时,我收到上述错误消息。

On both my Vista machine and my XP machine I'm finding that, if I don't click the button everything's fine, but if I do click the button I get the above error message when I close the application.

所以...我想知道这是否是一个错误,但同时我认为很有可能我不太了解如何在Delphi中使用TThreads的基本知识。我有点像Delphi新手,我害怕。

So... I'm wondering if this is a bug, but at the same time I think it's rather likely that I'm simply not understanding something very basic about how you're supposed to work with TThreads in Delphi. I am a bit of a Delphi newbie I'm afraid.

使用这样的TThread.CurrentThread有什么明显的错误吗?

Is there something obviously wrong with using TThread.CurrentThread like that?

如果没有,你有Delphi 2009,你是否得到同样的问题,如果你实现我的简单的样本项目?

If not, and you have Delphi 2009, do you get the same problem if you implement my simple sample project?

推荐答案

不幸的是,它似乎是一个与类别单元中最终确定部分的调用顺序:

Unfortunately it seems like a bug linked to the call order of the finalization section in the Classes unit:

DoneThreadSynchronization 清除 ThreadLock 结构,然后

FreeExternalThreads 想要销毁刚刚创建的Thread对象,当调用 CurrentThread

,要求在调用

EnterCriticalSection(ThreadLock) in TThread.RemoveQueuedEvents ...

DoneThreadSynchronization clears the ThreadLock structure, then
FreeExternalThreads wants to destroy the Thread object you just created when calling CurrentThread, and
that requires the ThreadLock to be already initialized in the call to
EnterCriticalSection(ThreadLock) in TThread.RemoveQueuedEvents...

更新

中有一个解决方法补丁 QC报告

这篇关于Delphi TThread.CurrentThread和EAccessViolation - 这是一个Bug还是我的无能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆