Guest User

Untitled

a guest
Jun 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. public class ThreadUtil {
  2. public static int UIThreadId;
  3.  
  4. public static void EnsureNotUIThread() {
  5. if ( Thread.CurrentThread.ManagedThreadId == UIThreadId ) {
  6. throw new InvalidOperationException("Bad thread");
  7. }
  8. }
  9. }
  10.  
  11. Interlocked.Exchange(ref ThreadUtil.UIThreadID, Thread.CurrentThread.ManagedThreadId);
  12.  
  13. public static bool IsBackground() {
  14. return null == SynchronizationContext.Current;
  15. }
Add Comment
Please, Sign In to add comment