Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown

丶灬走出姿态 提交于 2019-12-04 12:08:50

问题


I am getting an error in my simple project.

This is my code:

if (axZKFPEngX1.InitEngine() == 0) {
    label1.Text = "Connected";
}
else {
    label1.Text = "Connection Failed";
}

I already added reference composites AxInterop.ZKFPEngXControl and Interop.ZKFPEngXControl.

While debugging, I click the button, and a warning appears:

InvalidActiveXStateException was handled.

"Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown"**


回答1:


try to call CreateControl() from your component first.




回答2:


The answer by Constantin is Fulfill your requirement but here I wanted to add one more thing with it. If you wanted to reflected this changes via all the threads and not only by calling thread (in multiple thread scenario) then use

CreateControl();
InitWB();
SkinAllThreads();

Actually in multiple threading scenario if your skinning code is in one of the thread then may be it is not reflect change for other current thread so at that time this code is play important role in it.

Here is some Documents I mention kindly go through it for reference :

  1. initwb() method
  2. DirectSkin other Methods
  3. Adding Direct Skin to Application


来源:https://stackoverflow.com/questions/7240523/exception-of-type-system-windows-forms-axhostinvalidactivexstateexception-was

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!