c# - UI Thread .Invoke() causing handle leak? -


In what situations can the use of processes be increased due to continuous updation of a UI control from non-UI threads Is a representative and . Anvok-required ?

For example:

  Public Representative Zero Representative (UI Update); Private Zero UIUpdate () {if (someControl.InvokeRequired) {someControl.Invoke (New DelegateUIUpdate (UIUpdate)); Return; } // Do something with something. Control [/ code>  

When called on a loop or timer interval, the handle for the program increases steadily. Edit > Public Delegate DelegateUIUpdate (); Private Zero UIUpdate () {// if (someControl.InvokeRequired) // {// someControl.Invoke (New DelegateUIUpdate (UIUpdate)); // Return; //} checkerollegalcrossthreadcol = wrong; // do something with somethingControl}

... then increasing the handle stop , though I do not want to allow cross thread calls. <. / P>

Edit 2:

Here is a sample that increases the handle:

  thread thread; Private Representative Zero UpdateGUI (); Bool UpdateTheGui = false; Public Form 1 () {Initialization (); Thread = new thread (new threadstart (mitrate loop)); Thread.Start (); } Private Zero MyThreadLoop () {While (true) {Thread. Sleep (500); If (Update TheGui) {UpdateTheGui = false; UpdateTheGuiNow (); }}} Private Zero updateTheGuiNow () {if (label1.InvokeRequired) {label1.Invoke (New UpdateGUI (UpdateTheGuiNow)); Return; } Label1.Text = DateTime.Now Two string ("mm-dd-yyyy hh: mm: ss"); Label 2 Text = date time.NEW Two String ("MM-DD-YA HH: mm: SS"); Label 3 Text = date time.NEW Two String ("MM-DD-YA HH: mm: SS"); } Private Zero btnInvoke_Click (Object Sender, EventArgs e) {UpdateTheGui = True; } 

Control.Invoke () method does not consume any handle, however, This code is clearly called a thread, there is no displacement () method in the thread class in any of the

Thread class, However there should be one in it. It was possibly by design, it would be very difficult to call essentially Threadpool Threads very easily. 5 handles which requires a thread which is finally released. If your finalist never runs, your program will require a significant amount of handle.

Not getting the finalists to run is quite unusual. You will have an event that starts many threads but does not allocate all the memory, it only happens in static tests. You can diagnose this condition with Perfmon.exe, use the .NET Memory Performance Counter and check whether the # 0 is being collected.

If it is in a production program then you have to call GC. Gather yourself to avoid a runaway handle leak.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -