Breeze Breeze - 2 years ago 285 Question

How to use BeginInvoke in VB.NET

In C# you use

like this:

obj.BeginInvoke((Action)(() =>
//do something

I tried to translate it to VB.NET, and ended up with this code, that seems to work:

'do something'
End Sub

The snippets look very different to me, especially because the
(Action) (() =>
part is missing completely. Is this the correct way to use
in VB.NET?

Answer Source

(Action) just casts the lambda to an Action, which isn't needed in VB.NET. The Sub() lambda is all you need.

You have got the correct conversion.

Although note that BeginInvoke() must be followed by EndInvoke(), otherwise you will get thread leaks.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download