@@ -27,143 +27,6 @@ namespace Files.App.Helpers
2727	/// </summary> 
2828	public  static   partial  class  Win32Helper 
2929	{ 
30- 		public  static   Task  StartSTATask ( Func < Task >  func ) 
31- 		{ 
32- 			var  taskCompletionSource  =  new  TaskCompletionSource ( ) ; 
33- 			Thread  thread  =  new  Thread ( async  ( )  => 
34- 			{ 
35- 				Ole32 . OleInitialize ( ) ; 
36- 
37- 				try 
38- 				{ 
39- 					await  func ( ) ; 
40- 					taskCompletionSource . SetResult ( ) ; 
41- 				} 
42- 				catch  ( Exception  ex ) 
43- 				{ 
44- 					taskCompletionSource . SetResult ( ) ; 
45- 					App . Logger . LogWarning ( ex ,  ex . Message ) ; 
46- 				} 
47- 				finally 
48- 				{ 
49- 					Ole32 . OleUninitialize ( ) ; 
50- 				} 
51- 			} ) 
52- 
53- 			{ 
54- 				IsBackground  =  true , 
55- 				Priority  =  ThreadPriority . Normal 
56- 			} ; 
57- 
58- 			thread . SetApartmentState ( ApartmentState . STA ) ; 
59- 			thread . Start ( ) ; 
60- 
61- 			return  taskCompletionSource . Task ; 
62- 		} 
63- 
64- 		public  static   Task  StartSTATask ( Action  action ) 
65- 		{ 
66- 			var  taskCompletionSource  =  new  TaskCompletionSource ( ) ; 
67- 			Thread  thread  =  new  Thread ( ( )  => 
68- 			{ 
69- 				Ole32 . OleInitialize ( ) ; 
70- 
71- 				try 
72- 				{ 
73- 					action ( ) ; 
74- 					taskCompletionSource . SetResult ( ) ; 
75- 				} 
76- 				catch  ( Exception  ex ) 
77- 				{ 
78- 					taskCompletionSource . SetResult ( ) ; 
79- 					App . Logger . LogWarning ( ex ,  ex . Message ) ; 
80- 				} 
81- 				finally 
82- 				{ 
83- 					Ole32 . OleUninitialize ( ) ; 
84- 				} 
85- 			} ) 
86- 
87- 			{ 
88- 				IsBackground  =  true , 
89- 				Priority  =  ThreadPriority . Normal 
90- 			} ; 
91- 
92- 			thread . SetApartmentState ( ApartmentState . STA ) ; 
93- 			thread . Start ( ) ; 
94- 
95- 			return  taskCompletionSource . Task ; 
96- 		} 
97- 
98- 		public  static   Task < T ? >  StartSTATask < T > ( Func < T >  func ) 
99- 		{ 
100- 			var  taskCompletionSource  =  new  TaskCompletionSource < T ? > ( ) ; 
101- 
102- 			Thread  thread  =  new  Thread ( ( )  => 
103- 			{ 
104- 				Ole32 . OleInitialize ( ) ; 
105- 
106- 				try 
107- 				{ 
108- 					taskCompletionSource . SetResult ( func ( ) ) ; 
109- 				} 
110- 				catch  ( Exception  ex ) 
111- 				{ 
112- 					taskCompletionSource . SetResult ( default ) ; 
113- 					App . Logger . LogWarning ( ex ,  ex . Message ) ; 
114- 					//tcs.SetException(e); 
115- 				} 
116- 				finally 
117- 				{ 
118- 					Ole32 . OleUninitialize ( ) ; 
119- 				} 
120- 			} ) 
121- 
122- 			{ 
123- 				IsBackground  =  true , 
124- 				Priority  =  ThreadPriority . Normal 
125- 			} ; 
126- 
127- 			thread . SetApartmentState ( ApartmentState . STA ) ; 
128- 			thread . Start ( ) ; 
129- 
130- 			return  taskCompletionSource . Task ; 
131- 		} 
132- 
133- 		public  static   Task < T ? >  StartSTATask < T > ( Func < Task < T > >  func ) 
134- 		{ 
135- 			var  taskCompletionSource  =  new  TaskCompletionSource < T ? > ( ) ; 
136- 
137- 			Thread  thread  =  new  Thread ( async  ( )  => 
138- 			{ 
139- 				Ole32 . OleInitialize ( ) ; 
140- 				try 
141- 				{ 
142- 					taskCompletionSource . SetResult ( await  func ( ) ) ; 
143- 				} 
144- 				catch  ( Exception  ex ) 
145- 				{ 
146- 					taskCompletionSource . SetResult ( default ) ; 
147- 					App . Logger . LogInformation ( ex ,  ex . Message ) ; 
148- 					//tcs.SetException(e); 
149- 				} 
150- 				finally 
151- 				{ 
152- 					Ole32 . OleUninitialize ( ) ; 
153- 				} 
154- 			} ) 
155- 
156- 			{ 
157- 				IsBackground  =  true , 
158- 				Priority  =  ThreadPriority . Normal 
159- 			} ; 
160- 
161- 			thread . SetApartmentState ( ApartmentState . STA ) ; 
162- 			thread . Start ( ) ; 
163- 
164- 			return  taskCompletionSource . Task ; 
165- 		} 
166- 
16730		public  static   async  Task < string ? >  GetDefaultFileAssociationAsync ( string  filename ,  bool  checkDesktopFirst  =  true ) 
16831		{ 
16932			// check if there exists an user choice first 
0 commit comments