Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Task<T> StartSTATask<T>(Func<T> func)
- {
- var tcs = new TaskCompletionSource<T>();
- Thread thread = new Thread(() =>
- {
- try
- {
- tcs.SetResult(func());
- }
- catch (Exception e)
- {
- tcs.SetException(e);
- }
- });
- thread.SetApartmentState(ApartmentState.STA);
- thread.Start();
- return tcs.Task;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement