Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
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);
  ...
}



when i use this object in c#,it has this problem:
C#
//deal the ip change event 
void ipobj_IPChange(string para)
{        
            
      MessageBox.Show(s);              //the first line
      textBox14.Text = "change";       //the second line             
            
}

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]
Posted
Updated 8-Feb-12 21:07pm
v2

1 solution

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!
 
Share this answer
 
Comments
Espen Harlinn 9-Feb-12 9:35am    
5'ed!
china.net 15-Feb-12 3:20am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900