Skip to content

Commit 904f26b

Browse files
committed
Set GDAL_NUM_THREADS to 1 for x86 and x64.
Force the Form's own native window handle to exist even though it is not shown.
1 parent 5b82d6c commit 904f26b

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

‎MapWinGisTests-net/MapWinGisTests/LoaderWarmup.cs‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ private static void TryDelete(string path)
5858
private static void ConfigureGdal()
5959
{
6060
try {
61-
if(!Environment.Is64BitProcess)
62-
{
63-
// Forces GDAL to run raster operations single-threaded by setting the <c>GDAL_NUM_THREADS</c>
64-
// /// environment variable before any native GDAL/OCX module is loaded.
65-
if(string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GDAL_NUM_THREADS")))
66-
Environment.SetEnvironmentVariable("GDAL_NUM_THREADS", "1");
67-
}
61+
// Forces GDAL to run raster operations single-threaded by setting the <c>GDAL_NUM_THREADS</c>
62+
// /// environment variable before any native GDAL/OCX module is loaded.
63+
if(string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GDAL_NUM_THREADS")))
64+
Environment.SetEnvironmentVariable("GDAL_NUM_THREADS", "1");
6865
} catch {
6966
// Ignore
7067
}

‎MapWinGisTests-net/WinFormsApp1/Form1.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ protected override void WndProc(ref Message m)
8484
public void EnsureMapControlCreated()
8585
{
8686
CreateControl();
87+
88+
// Force the FORM's own native window handle to exist even though it is never
89+
// shown. Control.CreateControl() is a no-op while the control is invisible, so
90+
// in headless mode the form otherwise has no handle. That makes the teardown in
91+
// WinFormsTestRunner.DisposeFormWhilePumping fall back to a synchronous
92+
// form.Dispose(), which destroys the child window (and performs the blocking
93+
// cross-apartment UIA disconnect in Control.ReleaseUiaProvider) outside any
94+
// active message pump - the deadlock observed as a hang on the 32-bit (x86)
95+
// test host. Creating the handle here guarantees the pumped BeginInvoke +
96+
// Application.Run teardown path is used instead, which services that call.
97+
_ = Handle;
98+
8799
axMap1.CreateControl();
88100

89101
if(!axMap1.IsHandleCreated)

0 commit comments

Comments
 (0)