Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f562be

Browse files
committed
Start the wordpad demo in an STA thread.
This fixes the problem with the open and save dialogs freezing the application.
1 parent 53bd058 commit 9f562be

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

demo/wordpad.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import clr
1111
import System.Windows.Forms as WinForms
12+
from System.Threading import Thread, ThreadStart, ApartmentState
1213
from System.Drawing import Color, Size, Point
1314
from System.Text import Encoding
1415
from System.IO import File
@@ -420,12 +421,19 @@ def OnClickClose(self, sender, args):
420421
self.Close()
421422

422423

423-
424-
def main():
424+
def app_thread():
425425
app = Wordpad()
426426
WinForms.Application.Run(app)
427427
app.Dispose()
428428

429+
430+
def main():
431+
thread = Thread(ThreadStart(app_thread))
432+
thread.SetApartmentState(ApartmentState.STA)
433+
thread.Start()
434+
thread.Join()
435+
436+
429437
if __name__ == '__main__':
430438
main()
431439

0 commit comments

Comments
 (0)