Note that there are some explanatory texts on larger screens.

plurals
  1. POUI Thread .Invoke() causing handle leak?
    text
    copied!<p>In what circumstances would updating a UI control from a non-UI thread could cause the processes' handles to continually increase, when using a delegate and <code>.InvokeRequired</code>?</p> <p>For example:</p> <pre><code>public delegate void DelegateUIUpdate(); private void UIUpdate() { if (someControl.InvokeRequired) { someControl.Invoke(new DelegateUIUpdate(UIUpdate)); return; } // do something with someControl } </code></pre> <p>When this is called in a loop or on timer intervals, the handles for the program consistently increase.</p> <p><strong>EDIT:</strong></p> <p>If the above is commented out and amended as such:</p> <pre><code>public delegate void DelegateUIUpdate(); private void UIUpdate() { //if (someControl.InvokeRequired) //{ // someControl.Invoke(new DelegateUIUpdate(UIUpdate)); // return; //} CheckForIllegalCrossThreadCalls = false; // do something with someControl } </code></pre> <p>...then the handles <em>stop</em> incrementing, however I don't want to allow cross thread calls, of course.</p> <p><strong>EDIT 2:</strong></p> <p>Here is a sample that shows the handles increase:</p> <pre><code>Thread thread; private delegate void UpdateGUI(); bool UpdateTheGui = false; public Form1() { InitializeComponent(); thread = new Thread(new ThreadStart(MyThreadLoop)); thread.Start(); } private void MyThreadLoop() { while (true) { Thread.Sleep(500); if (UpdateTheGui) { UpdateTheGui = false; UpdateTheGuiNow(); } } } private void UpdateTheGuiNow() { if (label1.InvokeRequired) { label1.Invoke(new UpdateGUI(UpdateTheGuiNow)); return; } label1.Text = DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss"); label2.Text = DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss"); label3.Text = DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss"); } private void btnInvoke_Click(object sender, EventArgs e) { UpdateTheGui = true; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload