How to prevent control update thread time out?
The problem is it seems, is if the operation that updates a TextBox for example, with the property's value that it is bound to. If that property takes too long to produce said value the thread that is updating the textbox's value kills itself? (Im not sure on this, just assuming). This is causing me some issues with garbage collection and unmanaged code.
What I think is happening is the update thread dies and then my references to the unmanaged code are garbage collected, but the unmanaged code then executes but the object sent in from my managed code have been destroyed causing a fatal exception in my un-managed code.
Here is the warning associated with this problem: A callback was开发者_开发知识库 made on a garbage collected delegate of type '...'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.
Can someone tell me how I might go about preventing this problem?
Keep a reference of delegate in your class to prevent it from being garbage collected.
Read this for detail or read Collected delegate problem
Have you tried using IsAsync property of the Binding extension ?
{Binding ZZ, IsAsync=true}
that will put your execution delegate into ThreadPool and return back the result once it gets it, stops the GUI thread from blocking as well
精彩评论