Suppose that inside a Windows form, I run a long-running task as follows:
ThreadPool.QueueUserWorkItem(new WaitCallback(UpdateDailyTasksChart));
Then this function is executed for a while, but I close the window until it finishes.
private void UpdateDailyTasksChart (object param) {
And now here is what UICallback does:
private delegate void UICallbackDel(object chartData); private void UICallback (object chartData) { if (InvokeRequired) { this.Invoke(new UICallbackDel(UICallback), chartData); } else { aButtonOnMyForm.Visible = false;
Curiously, this code is not crashing.
I set breakpoints in the Form_Closed event and executed . I have not yet checked whether the form exists, for example, by declaring its class variable. But I guess that is so.
So the question is: will the GC only collect the form when my stream ends? Or what is happening?
Axonn source share