A BackgroundWorker for Avalon

I saw a post at the winfx.avalon newsgroup about the lack of support for a BackgroundWorker in Avalon (at least for v1.0). Since I need something like this for calling the Web Services asynchronously and then updating the Graphical User Interface, I just created a very simple one.

public class BackgroundWorker

{

  private UIContext _context;

  private UIContextOperationCallback _callback;

  public BackgroundWorker(UIContextOperationCallback callback)

  {

    _context = UIContext.CurrentContext;

    _callback = callback;

    Thread thread = new Thread(new ThreadStart(_run));

    thread.Start();

  }

  private void _run()

  {

    _context.Invoke(_callback, null);

  }

}

For the benefit of those who haven’t done any Windows GUI programming before, I have to say that a pattern like this is necessary because all the GUI elements must be updated by the same thread. The above makes sure that this happens.

UPDATE: Formatting fixed.

Recent Posts

BrainExpanded – Web app and Data Sources

As I wrote in previous posts, the manual recording of memories for BrainExpanded is just…

3 days ago

BrainExpanded – End-to-end working

Imagine a world where your memory is enhanced by a team of intelligent agents, working…

3 weeks ago

BrainExpanded – Login State Caching Issue in iOS Share Extension

As part of the BrainExpanded project, I’m building an iOS app that lets users easily…

2 months ago

Is AI Good or Bad?

Artificial Intelligence (AI) has rapidly evolved over the past few decades, becoming an integral part…

2 months ago

BrainExpanded – Copilot

Happy New Year everyone! I was planning for my next BrainExpanded post to be a…

4 months ago

BrainExpanded – The Timeline

See "BrainExpanded - Introduction" for context on this post. Notes and links Over the years,…

4 months ago