Reputation: 19
I read a file on disc in one ViewModel and at the end i send the data to another Viewmodel via the EventAggregator. When i switch to the View of the other Viewmodel (with ActivateItemAsync) it takes 10 seconds before the View opens ! The data consist of an ObservableCollection of some 80000 strings.In this 10 seconds the CPU usage is at 25%. What is happening in these 10 seconds ?
If i send only the filename to the other ViewModel and reread the file in the OnActivate method, the View opens in 2 seconds !
And what's the difference between Conductor<Screen>
and Conductor<Screen>.Collection.OneActive
?
I got a ShellVieModel : Conductor and all other ViewModels : Screen
public async void ReadNCfile()
{
LinesNC.Clear();
await Task.Run(() =>
{
Regex regexline = new Regex(@"^N[0-9]+");
int i = 1;
foreach (var rawline in File.ReadLines(SelectedNCItem))
{
LineNCFile line = new LineNCFile();
line.Index = i;
line.NCLine = rawline;
Match match = regexline.Match(rawline);
if (match.Success)
{
int number;
bool success = (Int32.TryParse((match.Value).Substring(1), out number));
if (success) line.LineNumber = number;
}
Application.Current.Dispatcher.Invoke(() =>
{
LinesNC.Add(line);
});
i++;
}
});
_eventAggregator.PublishOnUIThreadAsync(new NCFileChosenEvent(LinesNC));
}
Upvotes: 0
Views: 28