0

I am not sure how should I put the title of my question, But I have one issue in Window based application C# code.

basically I am creating 2 WPF application in C#

  1. For my First application, following steps are there

    A. I am Creating some folders by C# code and showing status on a TextBox.

    B. Then I am unzipping a folder by C# code and Copying files to a new folder location in C drive. This time also I have to show the status in TextBox.

But there is a problem with second step. Copying files blocked the first step to show the status in TextBox. I was hoping that It should show the status in TextBox first for the first step then it should start the coping files. Right now it shows the complete message in TextBox, after coping the files. :(

  1. For my second application, I load XML with more then 3000 data in a List. So Loading and displaying the items in the list, block the entire application. So how could I resolve this?

I am new in .net, so please help me in that.

VarunJi
  • 685
  • 2
  • 14
  • 31
  • 1
    This happens because you run your operations on the UI thread. You should read about UI thread in WPF to understand how you can prevent that. – Moti Azu Dec 10 '14 at 09:52
  • 1
    use the `BackgroundWorker` class for this problem – thumbmunkeys Dec 10 '14 at 09:55
  • 1
    Use TaskFactory for data collection & other time consuming tasks after initializing your control's and show progress window until all data fets fetched... – Amol Bavannavar Dec 10 '14 at 09:56

1 Answers1

2

You need to use Threads or Background Workers to accomplish this task. When you do some work in single application, your UI will get block till some Long Task get completed [in your case updating your text box].

Also to access UI components not inside your own thread [Original thread] you will need Invokes. Go through guides and try to adapt techniques in them. In my experience "Background workers" are easy to work with.

Guides -

Backgorund workers

Invokes

Updating UI- in your case show progress

Community
  • 1
  • 1
Kavindu Dodanduwa
  • 12,193
  • 3
  • 33
  • 46