1

I've got a WPF C# application that parses and loads a 1Gig text file. The current loading time for this app to parse the text file is approx 27 seconds. Therefore I would like to make an overlay circular dialog that displays the procentage of loading in the middle of the ListBox. Upon complete load the circular dialog must disappear.

Is it possible to keep this as a single-thread app?

I've spent the last couple of days looking at the web in search of a possible solution. The way I see it if at all possible then it must be a UserControl, but I haven't been able to find any straightforward solution?

My ListBox AXML:

<ListBox x:Name="listBoxTrackers" HorizontalAlignment="Left" Height="448" Margin="30,46,0,0" VerticalAlignment="Top" Width="740" SelectionChanged="listBoxTrackers_SelectionChanged" MouseDoubleClick="listBoxTrackers_MouseDoubleClick">
        [put the dialog overlay here]
    </ListBox>
ryokan
  • 125
  • 2
  • 12
  • I like this solution. http://wpf.2000things.com/tag/progressbar/ The point is not the part about drawing it your self but instead using the dispatchertimer. this a a mechanism that hitch hikes on the back of the rendering thread when it redraws parts of the screen. It's the same as registering to CompositionTarget.Rendering event. this way you do not handle propagation to the dispatcher. And the drawing will appear as smooth as possible ( though there are other tricks for doing that.) – eran otzap Nov 22 '15 at 15:11
  • an easier approach to utilize this mechanism : http://stackoverflow.com/questions/14485818/how-to-update-a-progress-bar-so-it-increases-smoothly – eran otzap Nov 22 '15 at 16:00
  • Isen't it possible to use a UserControl and put it inside the ListBox? – ryokan Nov 22 '15 at 16:04
  • you should incorporate an ItemsContainerStyle with a prograss bar in it – eran otzap Nov 22 '15 at 16:26
  • And here i was hoping that you'll post an actual test case + model and say when you wan't the prograssbar to appear. do you have an implementation of a circular prograss bar as well ? – eran otzap Nov 22 '15 at 18:13
  • I have looked at this one: http://www.codeproject.com/Articles/49853/Better-WPF-Circular-Progress-Bar – ryokan Nov 22 '15 at 21:08

1 Answers1

1

Which version of .NET are you using? From 4.0, what you would normally do is create an async function that reads the text file, call that function getting back a task, show an animated control overlayed on the control that is waiting, and then await the task you got back, and hide the animation again when complete.

Nicer of course would be to show a progress control, and have your text file parser post progress state that you assign to the progress control so your user can see the progress of the parsing. And of course you can show results in the list control while loading as well.

There are many options, but they are all going to be some form of multi-threading, but you shouldn't be afraid of that - the wpf user interface is built with that in mind.

In other words, take a look at the answer here: WPF ProgressBar usage when using Async/Await

Community
  • 1
  • 1
Arwin
  • 973
  • 1
  • 10
  • 21
  • I'm using .NET 4.5.2. I've tried await by this way: int t = await Task.Run(() => readFile(fileName)); but it throws an exception and says "cannot get access to the object because it is owned by another thread"? – ryokan Nov 22 '15 at 15:46