Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Windows Messag handling in C#

Windows Messag handling in C#

Scheduled Pinned Locked Moved C#
csharpc++helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vini Deep
    wrote on last edited by
    #1

    Hi, Is there any C# equivalent for SDK function 'MsgWaitForMultipleObjects()'? I want to implement this following c++ code in c#. Which is the right path to follow.

    bool CMyClass::MyFun()
    {
     unsigned  threadID;
     DWORD     waitResult;
     MSG       msg;
       
    
     writeSuccess = false;
     hThread = (HANDLE)_beginthreadex(NULL, 0,writeThread, NULL,0,&threadID);
    
     if (!hThread)
      return false;
    
     waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
     while (waitResult != WAIT_OBJECT_0)
     {
      if (waitResult == WAIT_OBJECT_0 + 1)
       while (PeekMessage(&msg, NULL,0,0,PM_REMOVE))
       {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
       }
      if (waitResult == WAIT_FAILED)
      {
       //An error occured, we need to handle it here
       break;
      }
       
      waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
     }
     CloseHandle(hThread);
    
     hThread = NULL;
    
     return writeSuccess;
    }
    

    I have read about the IMessageFilter interface of Microsoft.Win32 namespace. Is this the right way to proceed on this. Kindly advise. Vini

    S 1 Reply Last reply
    0
    • V Vini Deep

      Hi, Is there any C# equivalent for SDK function 'MsgWaitForMultipleObjects()'? I want to implement this following c++ code in c#. Which is the right path to follow.

      bool CMyClass::MyFun()
      {
       unsigned  threadID;
       DWORD     waitResult;
       MSG       msg;
         
      
       writeSuccess = false;
       hThread = (HANDLE)_beginthreadex(NULL, 0,writeThread, NULL,0,&threadID);
      
       if (!hThread)
        return false;
      
       waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
       while (waitResult != WAIT_OBJECT_0)
       {
        if (waitResult == WAIT_OBJECT_0 + 1)
         while (PeekMessage(&msg, NULL,0,0,PM_REMOVE))
         {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
         }
        if (waitResult == WAIT_FAILED)
        {
         //An error occured, we need to handle it here
         break;
        }
         
        waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
       }
       CloseHandle(hThread);
      
       hThread = NULL;
      
       return writeSuccess;
      }
      

      I have read about the IMessageFilter interface of Microsoft.Win32 namespace. Is this the right way to proceed on this. Kindly advise. Vini

      S Offline
      S Offline
      scadaguy
      wrote on last edited by
      #2

      WaitHandle.WaitOne uses MsgWaitForMultipleObjects. I know this because when it is called on the UI thread messages are still pumped.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups