/// <summary> /// Whenever you update your UI elements from a thread other than the main thread, you need to use: Dispatcher.BeginInvoke(new Action(() => {GetGridData(null, 0)})); /// https://stackoverflow.com/questions/9732709/the-calling-thread-cannot-access-this-object-because-a-different-thread-owns-it /// http://www.vbforums.com/showthread.php?731799-RESOLVED-WPF-Dispatcher-BeginInvoke-parameter-mismatch /// </summary> /// <param name="result"></param> private void StartProcessing(SourceFile result) { var file = new CurrentDispatcherFile() { Dispatcher = Dispatcher.CurrentDispatcher, SourceFile = result }; Task task = new Task(() => _listener.OnSourceLoaded(file)); task.Start(); }
public void OnSourceLoaded(object currentDispatcher) { CurrentDispatcherFile sourcefile = (CurrentDispatcherFile)currentDispatcher; sourcefile.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new RunProcessDelegate(RunProcess), sourcefile.SourceFile); }