Task continuation on UI thread

Is there a ‘standard’ way to specify that a task continuation should run on the thread from which the initial task was created? Currently I have the code below – it is working but keeping track of the dispatcher and creating a second Action seems like unnecessary overhead. dispatcher = Dispatcher.CurrentDispatcher; Task task = Task.Factory.StartNew(() … Read more

Do rails rake tasks provide access to ActiveRecord models?

I am trying to create a custom rake task, but it seems I dont have access to my models. I thought this was something implicitly included with rails task. I have the following code in lib/tasks/test.rake: namespace :test do task :new_task do puts Parent.all.inspect end end And here is what my parent model looks like: … Read more

When correctly use Task.Run and when just async-await

I would like to ask you on your opinion about the correct architecture when to use Task.Run. I am experiencing laggy UI in our WPF .NET 4.5 application (with Caliburn Micro framework). Basically I am doing (very simplified code snippets): public class PageViewModel : IHandle<SomeMessage> { … public async void Handle(SomeMessage message) { ShowLoadingAnimation(); // … Read more

How to safely call an async method in C# without await

I have an async method which returns no data: public async Task MyAsyncMethod() { // do some stuff async, don’t return any data } I’m calling this from another method which returns some data: public string GetStringData() { MyAsyncMethod(); // this generates a warning and swallows exceptions return “hello world”; } Calling MyAsyncMethod() without awaiting … Read more