How to block main thread without UI freeze

Posted by Sudhakar_A under WPF on 12/13/2013 | Points: 10 | Views : 4279 | Status : [Member] | Replies : 6
I have checkbox click event.......when i check the checkbox the code begin to execute line by line , in between some code- I want to display some text in the textbox inside the check event by blocking it's thread.

When i create any new thread to update textbox, it happens only after the checkbox click event is finished. I want to update the textbox before the checkbox click event.


Pls help me to sort out???????




Responses

Posted by: vishalneeraj-24503 on: 12/13/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Take another thread,and call a method,which will update your textbox like

class Program
{
static void Main()
{
Thread FirstThread = new Thread(new ThreadStart(Fun1));
FirstThread.Start();
}
public static void Fun1()
{
Textbox.Text = "hello";
}
}

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/13/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
You can also take Timer,which will invoke after a certain time period,and will update your textbox.

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nismeh on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
Try
Thread.Sleep(10000);

Hopefully this might work directly without creating any thread.

Write this line after adding text to text box.



IT KNOWLEDGE IS APPLIED KNOWLEDGE
So Just Do It

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhakar_A on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
@ Vishal neeraj......i m working in wpf application, i used dispatcher timer,but no use.

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhakar_A on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
@ Nismeh........... I initally used thread.sleep, but hanges ma UI.

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudhakar_A on: 12/13/2013 [Member] Starter | Points: 25

Up
0
Down
Thnks @Vishal & Nimesh

Sudhakar_A, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response