I'm having trouble understanding how to use threads. In a delegate that is called as needed to allow the user to select from a collection of projects, the first instantiation is costly due to data retrieval. The method looks like so:
private void _doStandAloneProjectPickSession(ProjectDataMode dataMode) {
var picker = new ProjectPicker();
var svc = _getFilterService(dataMode); ===> this is time consuming**
_vm = new ProjectSelectionViewModel(picker, svc);
_vm.RequestClose += _onClosing;
_window = picker;
_window.ShowDialog();
}
Is the basic idea to start the long running process in it's own thread (ie new Thread(doSomething).Start and then use the Dispatcher (in a wpf app) to cut in while the process is happening? I want to do something like the pseudo code below, but I can't get it to work.
private void _doStandAloneProjectPickSession(ProjectDataMode dataMode) {
...
// let user know the system is fetching data
// _getDispatcher.BeginInvoke(DispatcherPriority.Background, ()=>SetStaus("Fetching data...");
IProjectFilterService svc = null;
// fetch the data
// new Thread(_getFilterService(dataMode)).Start();
_vm = new ProjectSelectionViewModel(picker, svc);
_vm.RequestClose += _onClosing;
...
}
Can someone please show me what working code might look like?
Cheers,
Berryl