Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:52:28+00:00 2026-06-14T17:52:28+00:00

From the documentation I’ve realized that I can use Caliburn Micro’s coroutines for async

  • 0

From the documentation I’ve realized that I can use Caliburn Micro’s coroutines for async operations. Out of the box and without extra technologies. So I’ve implemented the next code in my Windows Phone app:

public class SimpleViewModel : Screen
{
    // ...

    protected override void OnViewLoaded(object view)
    {
        base.OnViewLoaded(view);

        Coroutine.BeginExecute(RunTask());
    }

    public IEnumerator<IResult> RunTask()
    {
        yield return new SimpleTask();
    }

    // ...
}

SimpleTask:

public class SimpleTask : IResult 
{
    public void Execute(ActionExecutionContext context)
    {
        Thread.Sleep(10000);
    }

    public event EventHandler<ResultCompletionEventArgs> Completed;
}

I’ve hoped that code in Execute method will run async. But this not happen. My UI-thread was blocked for 10 seconds.

Where I made a mistake? Or my assumption about async nature of coroutines was wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:52:29+00:00Added an answer on June 14, 2026 at 5:52 pm

    I spent the whole day searching for and trying code samples to finally have something that works (i.e. async operations using Caliburn Coroutines that do not block the UI), so I allow myself to share it.

    As far as I understand, Coroutines in Caliburn do not handle threads, they just provide an elegant way to have async execution and control code handled in one method. One has to use other tools such as BackgroundWorkers to process operations in background threads.

    I found this link pretty interesting, for silverlight. The aim was to include the background worker in a class that wraps coroutine calls.

    As I wanted it in WPF with slight differences, I ended up with this code sample that works on my machine:

    Wrapping class:

    using System;
    using Caliburn.Micro;
    using System.ComponentModel;
    
    namespace MyApp.Implementation
    {
        public class BackgroundCoRoutine : IResult
        {
            private readonly System.Action action;
    
            public BackgroundCoRoutine(System.Action action)
            {
                this.action = action;
            }
    
            public void Execute(ActionExecutionContext context)
            {
                using (var backgroundWorker = new BackgroundWorker())
                {
                    backgroundWorker.DoWork += (e, sender) => action();
                    backgroundWorker.RunWorkerCompleted += (e, sender) => Completed(this, new ResultCompletionEventArgs());
                    backgroundWorker.RunWorkerAsync();
                }
            }
    
            public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };
    
        }
    }
    

    And in one of my ViewModels, the following:

        public IEnumerable<IResult> ProcessTask()
        {
            IsBusy = true;
            TempObject result = null;
    
            for (int i = 1; i < 4; i++) // Simulates a loop that processes multiple items, files, fields...
            {
                yield return new BackgroundCoRoutine(() =>
                {
                    System.Threading.Thread.Sleep(1000); // Time consuming task in another thread
                    result = new TempObject("Item " + i);
                });
    
                MyObservableCollection.Add(result); // Update the UI with the result, in the GUI thread
            }
    
            IsBusy = false;
        }
    

    With this, when I click on the ProcessTask button, the UI is not frozen, and the computed results appear as soon as they are made available by the background worker process. The IsBusy state is not mandatory but shows how UI-related states can go into the async-oriented code.

    Hope this will help another me!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How i can use ArrayController in Ember.js 1.0pre? From documentation: MyApp.listController = Ember.ArrayController.create(); raises
I know from documentation we can find distance between two CLLocation points using the
From the documentation of UITableView / UITableViewController: If you decide to use a UIViewController
From the documentation: If the platform supports the unsetenv() function, you can delete items
As you can see from the documentation the way to start an Activity to
As far as I understand from the documentation the QUdpSocket are async but, still,
From the documentation's description, they seem to do the same thing except that not
I have read from documentation how can I set minheight and minwidth of modal
From documentation, I'm creating pma_history table. This is the only part of scripts/create_tables.sql that
I was trying to get some info from documentation, but it seems that it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.