You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
553 B
30 lines
553 B
using System;
|
|
using System.Threading;
|
|
|
|
public static class StaRunner
|
|
{
|
|
public static void Run(Action action)
|
|
{
|
|
Exception exception = null;
|
|
|
|
var thread = new Thread(() =>
|
|
{
|
|
try
|
|
{
|
|
action();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
exception = ex;
|
|
}
|
|
});
|
|
|
|
thread.SetApartmentState(ApartmentState.STA);
|
|
thread.Start();
|
|
thread.Join();
|
|
|
|
if (exception != null)
|
|
throw exception;
|
|
}
|
|
}
|