Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
i'm calling two functions simultaneously in a button click event.
 
                 label1.text="hai";
                JukeBox_Timer.Stop();
                JukeBox_Timer.Start();
 
<pre>
          thread.sleep(3000);
            clearfstext(pagenation_value);
 
            settheme(&quot;\\Page Selection.swf&quot;);</pre>

here i want to show the label then it waits for three second then the

settheme("\Page Selection.swf");
event come

but here is the problem that it does not show the label.text the thread sleeps and directly go to the function settheme("\Page Selection.swf");
Posted 12-Jul-13 1:58am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

lable1.Text = "hai"; doesn't get executed immediately. Like all GUI operations, it gets queued inernally until the next UI redraw. But the UI thread is blocked by thread.Sleep(3000);.

So you need to execute the sleep part in a worker thread. Something like
private void DelayedMethod()
{
    System.Threading.Thread.Sleep(3000);
 
<pre>
SetTheme("Whatever");

}

void YourCurrentMethodOnUiThread()
{
label1.Text = "hai";
 
System.Threading.Thread otherThread = new System.Threading.Thread(DelayedMethod);
otherThread.Start();

}
  Permalink  
Comments
Aatif Ali from Bangalore at 12-Jul-13 7:18am
   
Lukeer U r right..
Tricube at 13-Jul-13 0:02am
   
thanks lukeer itz working perfect.
Tricube at 13-Jul-13 1:18am
   
can you help with multithreading with the sleep like the above example
Tricube at 13-Jul-13 3:11am
   
shows an error while closing " COM object that has been separated from its underlying RCW cannot be used."
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

A simple solution is to force immediate redraw of the label using the Refresh method.
 
               label1.text="hai";
               label1.Refresh();  
               JukeBox_Timer.Stop();
               JukeBox_Timer.Start();
 
<pre>
           thread.sleep(3000);
           clearfstext(pagenation_value);
 
           settheme(&quot;\\Page Selection.swf&quot;);</pre>
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 335
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200
0 OriginalGriff 465
1 Sergey Alexandrovich Kryukov 275
2 ProgramFOX 265
3 Maciej Los 245
4 Andreas Gieriet 200


Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 12 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100