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

The Beginning of CVOYA

There’s a unique energy that comes with starting something new — a blend of excitement,…

3 weeks ago

Enhancements in Graph Model: Dynamic Entities & Full-Text Search

As I continued work on BrainExpanded and its MCP service, I came to realize that…

4 months ago

GraphModel: A .NET Abstraction for Graphs

Just over a month ago, I published "Playing with graphs and Neo4j". Back then, it…

5 months ago

Playing with graphs and neo4j

After my initial implementation of some BrainExpanded-related ideas on top of dgraph using its GraphQL…

6 months ago

A Graph Model DSL

Say hello to the Graph Model Domain Specific Language (GMDSL), created with the help of…

6 months ago

BrainExpanded – Web app and Data Sources

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

7 months ago