title: how to send data at any moment ( simultaneous ) in windows?
body: <p>I want write a namedpipe client in windows OS, which can send data at any time even the client is receiving data.<a href="https://docs.microsoft.com/zh-cn/windows/desktop/ipc/named-pipe-client" rel="nofollow noreferrer">Example</a> of MSDN only shows that sending data after receive something.And the serial operation is not what I want. Because the data I transfer between client and server is not so big,that is to say, IO operation should not be a time-consuming process, I didn't use <code>OVERLAP</code> in client.</p>
  
  <p>The code that I modify in MSDN example of client is as below:
  the main thread keep reading data, and the child-thread keep sending data to server. However, the server blocked when reading data when debugging.</p>
  
  <pre><code>std::thread t([&amp;] {
      cbToWrite = (lstrlen(lpvMessage) + 1) * sizeof(TCHAR);
      _tprintf(TEXT("Sending %d byte message: \"%s\"\n"), cbToWrite, lpvMessage);
  
  
      fSuccess = WriteFile(
          hPipe,                  // pipe handle
          lpvMessage,             // message
          cbToWrite,              // message length
          &amp;cbWritten,             // bytes written
          NULL);                  // not overlapped
  
      if (!fSuccess)
      {
          _tprintf(TEXT("WriteFile to pipe failed. GLE=%d\n"), GetLastError());
          return -1;
      }
  
      printf("\nMessage sent to server, receiving reply as follows:\n");
  
  });
  
  while (1)   // main thread always reading
  {
      do
      {
          // Read from the pipe.
  
          fSuccess = ReadFile(
              hPipe,    // pipe handle
              chBuf,    // buffer to receive reply
              BUFSIZE * sizeof(TCHAR),  // size of buffer
              &amp;cbRead,  // number of bytes read
              NULL);    // not overlapped
  
          if (!fSuccess &amp;&amp; GetLastError() != ERROR_MORE_DATA)
              break;
  
          _tprintf(TEXT("\"%s\"\n"), chBuf);
      } while (!fSuccess);  // repeat loop if ERROR_MORE_DATA
  
      if (!fSuccess)
      {
          _tprintf(TEXT("ReadFile from pipe failed. GLE=%d\n"), GetLastError());
          return -1;
      }
  }
  
  
  t.join();
  </code></pre>
  
  <p>I expect someone can correct that code to get it work, or can you tell the standard practice or suggestions? 
  Thanks so much!</p>