Browse Source

Fix crash when opening start page.

pull/32/merge
Daniel Grunwald 13 years ago
parent
commit
a07f492feb
  1. 43
      src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml.cs

43
src/AddIns/Misc/StartPage/Project/Src/RecentProjectsControl.xaml.cs

@ -8,6 +8,7 @@ using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Documents; using System.Windows.Documents;
@ -40,35 +41,31 @@ namespace ICSharpCode.StartPage
set { SetValue(HeaderProperty, value); } set { SetValue(HeaderProperty, value); }
} }
async void BuildRecentProjectList()
void BuildRecentProjectList()
{ {
// When building the project list we access the .sln files (to see if they still exist). // When building the project list we access the .sln files (to see if they still exist).
// Because those might be stored on a slow network drive, we do this on a background thread so that // Because those might be stored on a slow network drive, we do this on a background thread so that
// SharpDevelop startup doesn't have to wait. // SharpDevelop startup doesn't have to wait.
ThreadPool.QueueUserWorkItem(AsyncBuildRecentProjectList, SD.FileService.RecentOpen.RecentProjects.ToArray()); var projectPaths = SD.FileService.RecentOpen.RecentProjects.ToArray();
}
void AsyncBuildRecentProjectList(object state)
{
List<RecentOpenItem> items = new List<RecentOpenItem>(); List<RecentOpenItem> items = new List<RecentOpenItem>();
foreach (string path in (string[])state) { await Task.Run(
Core.LoggingService.Debug("RecentProjectsControl: Looking up path '" + path + "'"); delegate {
FileInfo file = new FileInfo(path); foreach (FileName path in projectPaths) {
if (file.Exists) { Core.LoggingService.Debug("RecentProjectsControl: Looking up path '" + path + "'");
items.Add( FileInfo file = new FileInfo(path);
new RecentOpenItem { if (file.Exists) {
Name = Path.GetFileNameWithoutExtension(path), items.Add(
LastModification = file.LastWriteTime.ToShortDateString(), new RecentOpenItem {
Path = path Name = Path.GetFileNameWithoutExtension(path),
}); LastModification = file.LastWriteTime.ToShortDateString(),
} Path = path
} });
}
}
});
if (items.Count > 0) { if (items.Count > 0) {
SD.MainThread.InvokeAsyncAndForget(new Action(delegate { lastProjectsListView.ItemsSource = items;
lastProjectsListView.ItemsSource = items; lastProjectsListView.Visibility = Visibility.Visible;
lastProjectsListView.Visibility = Visibility.Visible;
}));
} }
} }

Loading…
Cancel
Save