title: WPD MTP stream hangs on commit
body: <p>I am using the following code to copy a file wrapped by a FileInfo object to an MTP device using the Windows Portable Device API:</p>
  
  <pre><code>public static void CopyFileToDevice(PortableDeviceFolder parent, string name, FileInfo file)
      {
          IPortableDeviceValues values = GetRequiredPropertiesForContentType(parent.Id, name, file.Length);
  
          PortableDeviceApiLib.IStream tempStream;
          uint blockSize = 0;
          parent.Device.Content.CreateObjectWithPropertiesAndData(
              values,
              out tempStream,
              ref blockSize,
              null);
  
          System.Runtime.InteropServices.ComTypes.IStream targetStream =
              (System.Runtime.InteropServices.ComTypes.IStream)tempStream;
          try
          {
              using (var sourceStream = file.OpenRead())
              {
                  var buffer = new byte[blockSize];
                  int bytesRead;
                  do
                  {
                      bytesRead = sourceStream.Read(buffer, 0, (int)blockSize);
                      targetStream.Write(buffer, bytesRead, IntPtr.Zero);
                  } while (bytesRead &gt; 0);
              }
  
              targetStream.Commit(0);
          }
          finally
          {
              Marshal.ReleaseComObject(tempStream);
          }
          parent.Refresh();
      }
  </code></pre>
  
  <p>Now, this works quite fine, however when writing a small file, in this case a text-only .m3u file of a couple of kiB, the line</p>
  
  <pre><code>targetStream.Commit(0);
  </code></pre>
  
  <p>takes extremely long to execute. When writing a file of several MiB, nothing is wrong.
  I would like to know why this is happening and how I might fix this. Thanks!</p>