c# - Thread updating GUI freezes in random moments -


i have form button , text box. button starting thread updating value of text box.

    public form1()     {         initializecomponent();         mydelegate = new updateui(updateui);     }     private void button1_click(object sender, eventargs e)     {         mythread = new thread(new threadstart(threadfunction));         mythread.start();     }     private void threadfunction()     {         mythreadclass mythreadclassobject  = new mythreadclass(this);         mythreadclassobject.run();     }     private void updateui(int i)     {         textbox1.text = i.tostring();         thread.sleep(1000);     }     public thread mythread;     public delegate void updateui(int i);     public updateui mydelegate; 

and threadclass:

public class mythreadclass {     form1 myformcontrol1;     public mythreadclass(form1 myform)     {         myformcontrol1 = myform;     }      public void run()     {         // execute specified delegate on thread owns         // 'myformcontrol1' control's underlying window handle.         for(int i=0;i<100;i++)         {             if(myformcontrol1.invokerequired)             {                 myformcontrol1.invoke(myformcontrol1.mydelegate,i);             }          }       } } 

as can see there nothing special in code code freeze.

eg goes 1->2->3->freeze->16->17 , on.

i took code here little modifications

the issue delaying ui thread not the process happens issue update commands since runs on same thread gets clogged because thread.sleep stops ui thread runs bunch of textbox1.text = i.tostring(); stops time of thread.sleep(1000); number of 1->2->3... see equal number of cores in machine.

when stop run method happens issue 1 update command runs , wait 1 second until issue next command witch think trying accomplish.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -