Skip to content

Instantly share code, notes, and snippets.

@GeorgDangl
Last active January 30, 2020 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgDangl/b40a23b441be1575ac169d99d11e9f44 to your computer and use it in GitHub Desktop.
Save GeorgDangl/b40a23b441be1575ac169d99d11e9f44 to your computer and use it in GitHub Desktop.
Workaround to accessing the Revit API from other threads, see https://blog.dangl.me/archive/accessing-the-revit-api-in-callbacks-from-other-threads/
var callbackStack = new Stack<Action>();
uiapp.Idling += (s, e) =>
{
if (callbackStack.Any())
{
var action = callbackStack.Pop();
action.Invoke();
}
};
JavaScriptBridge
.Instance
.OnWebUIMessageReveived += (s, e) =>
{
callbackStack.Push(() =>
{
// You can safely access the Revit API here
});
};
JavaScriptBridge
.Instance
.OnWebUIMessageReveived += (s, e) =>
{
// Accessing the Revit API here fails
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment