As a simple example I have a WPF application with a single button on the Main Window and code behind thus:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
async void Button_Click(object sender, RoutedEventArgs e)
{
await Task<bool>.Run(() => this.DoOnThread());
}
async Task<bool> DoOnThread()
{
Thread.CurrentThread.Name = "MyTestThread";
Thread.Sleep(1000);
return true;
}
}
If I break at "return true" via VisualStudio threads window I can get the ThreadID, if I continue and let the code run to completion and wait a little till the thread exits, I get "The thread 0x9ad34 has exited with code 259 (0x103)" displayed in the VS output window.
What am I doing wrong and how do I ensure I get a thread exit code of 0?