It seems that in this case the object will be destroyed before the delegate in BeginInvoke fires in the user interface thread
Finalizer queues work in the user interface message loop. An object can complete its finalizer method before the actual delegate is called in the user interface thread, but this does not matter since the delegate receives a queue in the queue.
What's going on here?
You start work with the user interface from the finalizer.
It's safe?
Safe is a broad term. Would I do it? Absolutely not. It seems odd that you are invoking manipulation of the user interface elements from the finalizer, especially considering that it is a TextBox control. I suggest you fully understand that the finalizer works and does not guarantee. Firstly, starting the finalizer does not mean that the object is immediately cleared in memory.
I also suggest reading @EricLippert posts: why is everything you know wrong, Part1 and Part 2
Yuval Itzchakov
source share