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

Digital Twin (my playground)

I am embarking on a side project that involves memory and multimodal understanding for an…

9 months ago

“This is exactly what LLMs are made for”

I was in Toronto, Canada. I'm on the flight back home now. The trip was…

1 year ago

AI is enhancing me

AI as an enhancer of human abilities.

1 year ago

“How we fell out of love with voice assistants”

The BBC article "How we fell out of love with voice assistants" by Katherine Latham…

2 years ago

Ontology-based reasoning with ChatGPT’s help

Like so many others out there, I played a bit with ChatGPT. I noticed examples…

2 years ago

Break from work

Hi all… It’s been a while since I posted on this blog. It’s been an…

2 years ago