Skip to content

Commit f51c21f

Browse files
added a test for ShowDialog re-entry (#12944)
1 parent 12d120b commit f51c21f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/OpenFileDialogTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ public void ShowDialog_ResultWithMultiselect()
4545
Assert.Equal(tempFile.Path, dialog.FileName);
4646
}
4747

48+
// Regression test for https://github.com/dotnet/winforms/issues/12847
49+
[WinFormsFact]
50+
public void ShowDialog_Twice()
51+
{
52+
using OpenFileDialog dialog = new();
53+
using var tempFile = TempFile.Create(0);
54+
dialog.Multiselect = true;
55+
dialog.InitialDirectory = Path.GetDirectoryName(tempFile.Path);
56+
dialog.FileName = tempFile.Path;
57+
58+
using RaceConditionDialogForm dialogOwnerForm = new(dialog);
59+
Assert.Equal(DialogResult.OK, dialog.ShowDialog(dialogOwnerForm));
60+
}
61+
62+
private class RaceConditionDialogForm : AcceptDialogForm
63+
{
64+
private readonly OpenFileDialog _dialog;
65+
66+
public RaceConditionDialogForm(OpenFileDialog dialog)
67+
{
68+
_dialog = dialog;
69+
}
70+
71+
protected override void OnDialogIdle(HWND dialogHandle)
72+
{
73+
Assert.Equal(DialogResult.Cancel, _dialog.ShowDialog(this));
74+
base.OnDialogIdle(dialogHandle);
75+
}
76+
}
77+
4878
private class AcceptDialogForm : DialogHostForm
4979
{
5080
protected override void OnDialogIdle(HWND dialogHandle)

0 commit comments

Comments
 (0)