title: WebRTC for UWP, new RTCPeerConnection() doesn't complete execution
body: <p>I’m trying to create a Universal Windows Platform application that uses WebRTC, but my code never executes past the first new RTCPeerConnection.</p>
  
  <p>I have been looking at the open source project WebRTC for UWP (<a href="https://blogs.windows.com/buildingapps/2017/02/22/real-time-communications-universal-windows-platform-webrtc-ortc/#0wD7JbH0MOcjDyDX.97" rel="nofollow noreferrer">blog post</a> with links to git repos) and managed to build and run the ChatterBox VoIP client example. Since I am new to both UWP programming and WebRTC (and .NET, C# and Windows programming in general) the examples I have been looking at in the repos mentioned above have been much too complex for me to follow.</p>
  
  <p>To start with something simpler, I want to recreate the WebRTC.org minimalistic <a href="https://codelabs.developers.google.com/codelabs/webrtc-web/index.html?index=..%2F..%2Findex#4" rel="nofollow noreferrer">codelab exercise</a> as a UWP application written in C#. The original HTML/javascript creates a webpage with two video streams, one that is the local videostream and one that is sent over WebRTC. But, my UWP code doesn’t even get past creating the first RTCPeerConnection.</p>
  
  <p>I am using Visual Studio 2015 and have installed the Nuget WebRTC package for UWP.</p>
  
  <p><strong>My code, first version</strong></p>
  
  <pre><code>public sealed partial class MainPage : Page
  {
      RTCPeerConnection _pc1;
      public MainPage()
      {
          this.InitializeComponent();
      }
      // Code that is executed when ‘Call’ button is clicked
      private async void uxCall_Click(object sender, RoutedEventArgs e)
      {
          /* GetDefaultList() returns List&lt;RTCIceServer&gt;, with Stun/Turn-servers borrowed from the ChatterBox-example */
          var config = new RTCConfiguration() { IceServers = GetDefaultList() };
          pc1 = new RTCPeerConnection(config);
          Debug.WriteLine(“Never reaches this point”);
      }
  }
  </code></pre>
  
  <p>Debugging and printouts shows that the statement after the creation of the new RTCPeerConnection is never reached. I thought that maybe creating a new RTCPeerConnection couldn’t be done on the main thread, so I updated the code to run that code on another thread.</p>
  
  <p><strong>My code, second version</strong></p>
  
  <pre><code>public sealed partial class MainPage : Page
  {
      RTCPeerConnection _pc1;
      public MainPage()
      {
           this.InitializeComponent();
      }
      // Code that is executed when ‘Call’ button is clicked
      private async void uxCall_Click(object sender, RoutedEventArgs e)
      {
           var config = new RTCConfiguration() { IceServers = GetDefaultList() };
           _pc1 = await CreatePeerConnection(config);
           Debug.WriteLine(“Never reaches this point”);
      }
  
      private async Task&lt;RTCPeerConnection&gt; CreatePeerConnection(RTCConfiguration config)
      {
           RTCPeerConnection pc;
           Debug.WriteLine("Creating peer connection.");
           pc = await Task.Run(() =&gt; {
                 // A thread for the anonymous inner function has been created here
                 var newpc = new RTCPeerConnection(config);
                 Debug.WriteLine("Never reaches this point");
                 return newpc;
           });
           return pc;
       }
  }
  </code></pre>
  
  <p>Debug printouts show that the code doesn’t reach the line after the creation of the new RTCPeerConnection. Debugging shows that the thread created for the anonymous inner function is never destroyed. I have tried to use an empty RTCConfiguration like in the codelab exercise, but it makes no difference.</p>
  
  <p>My inexperience with WebRTC, UWP and asynchronous/thread programming in UWP makes is difficult for me to determine where the error is. Any help would be greatly appreciated.</p>