当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Backgroundworker in a Winform Usercontrol in an ActiveX Control crashing the ActiveX

问题描述:

I've written an ActiveX-Control with a bindable property.

The ActiveX consists of a single Dialog that shows a WinForms UserControl (via CWinFormsControl<..>).

When the ActiveX property changes, a function on the Usercontrol is called which then should do some database calls and display the results.

So far everything works.

Now when I want to move the database queries to a BackgroundWorker, but everytime I call my database functions in the backgroundworker, the ActiveX-Control crashes. The UserControl on it's own (in a normal WinForms-Application) is running fine.

Any idea how I can find what's wrong here? Are there general pitfalls with Threads and ActiveX-Controls I'm not aware of?

网友答案:

ActiveX control is thread-affinity, only the thread(usually is main windows thread) which create the ActiveX control can call into the control's property setting/function call. Otherwise, the control will crash. If the background worker thread want to notify or call back to control, the best way is post windows message to control, and let control's creating thread to reponse to message and do what ever you want to do.

分享给朋友:
您可能感兴趣的文章:
随机阅读: