关于activex,线程和事件的一些问题 [英] some question about activex ,thread and event

查看:86
本文介绍了关于activex,线程和事件的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

啊,一个星期真糟糕,我走不通.请帮忙.

我使用atl(vs2005).code创建一个简单的对象,如:

ahh,its so bad a week,i can''t get the way. Plz,someone help .

i create a simple object using atl(vs2005).code like:

DWORD WINAPI IPEventProc( LPVOID lpParameter)
{
   OVERLAPPED overlap;
   DWORD ret;
   HANDLE handle;
   handle=NULL;
   overlap.hEvent = WSACreateEvent();
   ret = NotifyAddrChange(&handle, &overlap);
   if(WaitForSingleObject(overlap.hEvent, INFINITE) == WAIT_OBJECT_0 )	
   {
      //here trigger event
      Fire_IPChange(L"darling , i'm coming...");
 
   }
   
}
StartNotifyAddrChange(VARIANT_BOOL* bSucc)
{
  ...
  CreateThread(NULL,0,IPEventProc,0,CREATE_SUSPENDED,&tid);
  SetThreadPriority(tHandle,THREAD_PRIORITY_IDLE);
  ResumeThread(tHandle);
  ...
}




当我在C#中使用此对象时,出现了以下问题:




when i use this object in c#,it has this problem:

//deal the ip change event 
void ipobj_IPChange(string para)
{        
            
      MessageBox.Show(s);              //the first line
      textBox14.Text = "change";       //the second line             
            
}


当ip更改时,第一行可以正确运行.但是第二行什么也没运行,什么也没发生,为什么?

当只有第一行就可以了!

当仅第二行不起作用时.

请给我一些建议.

[edit]添加了代码块-OriginalGriff [/edit]


when ip changed ,the first line can run correctly. but the second line runs nothing ,just nothing happend ,why ?

when only the first line ,it''s ok!

when only the second line ,it''s not work.

Please,give me some advice.

[edit]Code block added - OriginalGriff[/edit]

推荐答案

您需要将调用调用到ui线程中,因为调用线程不是主线程.因此,您甚至很幸运没有遇到例外.请查看示例链接: http://blogs.msdn. com/b/csharpfaq/archive/2004/03/17/91685.aspx [
You would need to invoke the call into the ui thread because the calling thread is not the main thread. You even got lucky not to get an exception because of this. Have a look at the link for an example: http://blogs.msdn.com/b/csharpfaq/archive/2004/03/17/91685.aspx[^]

Good luck!


这篇关于关于activex,线程和事件的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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