Asynchronous Delegates

Hello guys,
I’d like to use asynchronous delegates, but it doesn’t seem to work.
The IronRuby website mentioned that I can do:

require ‘System’
=> true

require ‘System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’
=> true

my_action = { puts “Howdy!” }
=> System.Action

=> nil

That works fine, but if I try this instead:

result = my_action.BeginInvoke(nil,nil)

I get:

System::NullReferenceException: Object reference not set to an instance
of an object.

Am I missing something, or is there another way to do asynchronous
delegates in IR.

Thanks in advance,


Hi Bassel,

Ruby provides its own support for asynchronous operations in its Thread
class: do
puts “howdy!”

If you specifically need to run a .NET delegate asynchronously, you can
its invoke method within this structure: do

More info on Ruby’s Thread class:

Does that meet your needs?


or take a look here: I think the threadpool code is the one you want but
it’s commented out right now

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
GSM: +32.486.787.582
Author of IronRuby in Action (

Thanks guys. I ended up writing a wrapper that takes an action and runs
it in an async delegate and that worked fine. You can obviously get
much fancier, but an example would be along the lines of this:

C# class:
public class WrapInDelegate{
public delegate void DelegateWrapper();
public DelegateWrapper wrapper;
public WrapInDelegate(Action a){
wrapper = delegate(){a.Invoke();};

    public IAsyncResult  BeginInvoke(){
        return wrapper.BeginInvoke(null, null);

    public void EndInvoke(IAsyncResult result){

From Ruby:
d = { puts “I run for no
man…” })
r = d.BeginInvoke
d.EndInvoke r