c# - Check If Thread Is on Gui Context -
how can check if current running thread on gui context or not?
it's unfortuntaley hard answer question 100% accuracey because it's not entirely obvious constitutes gui context. it's more of heuristic yes / no answer. , heuristic different every gui framework.
for wpf 1 check , see if there active dispatcher
current thread
public static bool iswpfguithread() { return dispatcher.fromthread(thread.currentthread) != null; }
however can fooled setting dispather
on random thread not putting gui on top of it.
for winforms 1 check current synchronizationcontext
.
public static bool iswinformsguithread() { return synchronizationcontext.current windowsformssynchronizationcontext; }
however can fooled temporarily (or longer) reseting current
value synchronization context. thread global , can set anyone. it's common change in applications visual studio (but that's wpf app though)
Comments
Post a Comment