Try adding a special line to Main:
[STAThread]
static void Main( )
{
WindowsFormsSynchronizationContext.AutoInstall = false;
Form form = new Form( );
new TaskTest( ).OnWork( ).Wait( );
}
class TaskTest
{
public async Task OnWork( )
{
Trace.WriteLine( "start" );
await Task.Run( ( ) => { Trace.WriteLine( "work" ); } );
Trace.WriteLine( "end" );
}
}
However, it is not clear why one code works or hangs.