请教线程问题?

impeng 2003-09-26 04:51:21
我在一个ActiveX控件中启动了一个线程,但当我从这个线程中fire一个该ActiveX的事件的时候,系统却报内存访问错误,不知道是什么原因 --界面代码是用的VB。

另外想知道一下怎样才能在这样的线程中触发这样的事件?谢谢
...全文
82 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
impeng 2003-09-27
  • 打赏
  • 举报
回复
wuxfBrave,不是参数转换的问题,因为同样的事件在ActiveX的主线程中fire就没有问题。
Onega() 提供了一些线索,非常感谢,但英文看起来太累,我很少看原版的资料,因此在理解上也有问题。
wuxfBrave 2003-09-27
  • 打赏
  • 举报
回复
up,VB?是不是参数转换格式的问题
wuxfBrave 2003-09-27
  • 打赏
  • 举报
回复
Apartment-threading, while allowing for multiple threads of execution, serializes all incoming calls by requiring that calls to methods of objects created by this thread always run on the same thread – the apartment/thread that created them. In addition, calls can arrive only at message-queue boundaries (i.e., only during a PeekMessage, SendMessage, DispatchMessage, etc.). Because of this serialization, it is not typically necessary to write concurrency control into the code for the object, other than to avoid calls to PeekMessage and SendMessage during processing that must not be interrupted by other method invocations or calls to other objects in the same apartment/thread.
impeng 2003-09-27
  • 打赏
  • 举报
回复
在msdn中找到方法了,ms还是推荐用发送消息的方式
下面是msdn中对应的title:
“Fireev.exe Fires Events from a Second Thread”

不过还是没弄清楚出错的原因,只知道和apartment有关。奇妙..
不知道哪位能给出合理的解释?
Onega 2003-09-26
  • 打赏
  • 举报
回复
http://www.codeguru.com/atl/ThreadEvents.shtml
ATL: Firing Events from Worker Threads - Michael Lindig (2000/07/16)
Very cool solution to common problem of firing events from the worker thread of an ATL component

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧