# .NET delegates, asynchronousness and such

**URL:** <https://www.ruby-forum.com/t/net-delegates-asynchronousness-and-such/140956>\
**Category:** IronRuby\
**Created:** [June 20, 2008, 5:20am UTC](https://www.ruby-forum.com/t/net-delegates-asynchronousness-and-such/140956 "2008-06-20T05:20:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![barby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c57346/32.png) [@barby](https://www.ruby-forum.com/u/barby)\
**Post date:** [June 20, 2008, 5:20am UTC](https://www.ruby-forum.com/t/net-delegates-asynchronousness-and-such/140956/1 "2008-06-20T05:20:56Z")

</div>

Hi

I want to execute a delegate asynchronously with something like  
Action.BeginInvoke that doesn’t seem to work, also using  
BackgroundWorker I  
get no result.

bw = System::ComponentModel::BackgroundWorker.new  
bw.do\_work { #do some work here, but never seems to get executed }

in C# public delegate void VoidHandler();  
in IronRuby: VoidHandler.new{ #do some work her, but never seems to get  
executed }.begin\_invoke(nil, nil)

So  
VoidHandler.new{ File.open(‘threading.txt’, ‘w’){ |f| f \<\< “writing from  
thread” } }.begin\_invoke(nil, nil)

never creates the file threading.txt

But using the ThreadPool myself does work properly and creates a file  
threading2.txt

> > > $cb = WaitCallback.new { File.open(“threading2.txt” , ‘w’){|f| f \<\<  
> > > “From Thread” }  
> > > =\> #System::Threading::WaitCallback:0x0000066
> 
> > > System::Threading::ThreadPool.queue\_user\_work\_item $cb, nil  
> > > =\> true

Thanks  
Ivan
