I am wondering about the following:
I have an observable collection named Container and method named Method.
On the main thread I want to add the returned value from Method to the Container.
The following code runs on another thread, so I have to Invoke the Container.Add to the app current thread to not have errors:
object obj = Method()
App.Current.Dispatcher.Invoke(() => {
Container.Add((MyObject)obj)
});
My question is if I would do the following
App.Current.Dispatcher.Invoke(() => {
Container.Add((MyObject)Method())
});
The method (which is a long running method) will run on the app current thread, which is not quite correct because it will hand the UI, could I invoke only the returned value of the method to be added to the Container without defining the object like in the first example?