Global variable that only exists during initial call + async continuations
Hey so in my app I have a transition from void to async. During the initial call to the async part (the synchronous part) and all continuations, I want to be able to set a global variable, and only for continuations that originate from that original call. This is so that I can associate different globals to the same async call.
The void to async part also happens on my app's main thread, and continuations ofc only run on the main thread.
Is there a way to do this?
3 Replies
For example:
ShowOpenFileDialog
would access the current CurrentWindow
so that it can be shown as a modal dialog
But if some work gets done or someone does Task.Delay
before showing the file dialog, then CurrentWindow
will be reset to null
That seems to work nice
It actually works perfectly i didn't expect it to work at all
Code doesn't fail at alluse AsyncLocal<T> to flow a contextual value across the async call and its continuations on the main thread, so each original invocation carries its own associated global
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View