Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm calling two functions simultaneously in a button click event.



C#
   label1.text="hai";
  JukeBox_Timer.Stop();
  JukeBox_Timer.Start();

thread.sleep(3000);
  clearfstext(pagenation_value);

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



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

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
C#
private void DelayedMethod()
{
    System.Threading.Thread.Sleep(3000);

    SetTheme("Whatever");
}

void YourCurrentMethodOnUiThread()
{
    label1.Text = "hai";

    System.Threading.Thread otherThread = new System.Threading.Thread(DelayedMethod);
    otherThread.Start();
}
 
Share this answer
 
Comments
Aatif Ali from Bangalore 12-Jul-13 7:18am    
Lukeer U r right..
Tricube 13-Jul-13 0:02am    
thanks lukeer itz working perfect.
Tricube 13-Jul-13 1:18am    
can you help with multithreading with the sleep like the above example
Tricube 13-Jul-13 3:11am    
shows an error while closing " COM object that has been separated from its underlying RCW cannot be used."
A simple solution is to force immediate redraw of the label using the Refresh method.

C#
label1.text="hai";
label1.Refresh();
JukeBox_Timer.Stop();
JukeBox_Timer.Start();

thread.sleep(3000);
clearfstext(pagenation_value);

settheme("\\Page Selection.swf");
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900