title: Trying to understand when std::thread is supposed to start after detach within an MFC app
body: <p>Using Win11; VS2019; C++; SDK 10.0.22621.0; Platform Toolset VS 2019; C++ Language Standard C++17; NuGet CppWinRT 2.0.220608.4</p>
  <p>Normally, if I have a process that I want to send off to complete on its own, I start a <code>std::thread</code> and then <code>detach</code> it like this:</p>
  <pre><code>std::thread FindBleDeviceThread(FindBleDevice);
  FindBleDeviceThread.detach();
  </code></pre>
  <p>In this case, however, I see -- maybe I am only noticing this for the first time -- that the code in the <em>FindBleDevice</em> function does not even start until after I leave the current calling function to briefly go to a DialogBox.  Maybe this is normal behavior and I had just never noticed the delay before.</p>
  <p>In this case the <em>FindBleDevice</em> is a function using <code>C++/WinRT</code> code to start a <code>watcher</code> to look for a specific Bluetooth LE device and, once it is found, to call a separate function to Open it.</p>
  <pre><code>void FindBleDevice() {
    bDeviceOpened = false; // This first line never starts until the DialogBox is called.
    // Find device code here
    OpenDevice(deviceAddress); // IAsyncAction function
    return;
  }
  </code></pre>
  <p>The <em>OpenDevice</em> function is:</p>
  <pre><code>winrt::Windows::Foundation::IAsyncAction OpenDevice(unsigned long long deviceAddress){
    auto device = co_await BluetoothLEDevice::FromBluetoothAddressAsync(deviceAddress);
    // More code here to get GATT Services and Characteristics and do a few writes to the Tx characteristic.
  }
  </code></pre>
  <p>The call to <em>FindBleDevice</em> is within a function which was called from the app's main thread. The <em>FindBleDevice</em> thread is started and detached and nothing happens in the <em>FindBleDevice</em> code (not even the first line of code) until a DialogBox is called getting us briefly out of the function that called the thread.</p>
  <p>What am I missing here?  Why would that <em>FindBleDevice</em> thread not run on it's own as I would expect but instead wait until we are out of the calling function?</p>