Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anonymous methods - C# to VB.NET

I have a requirement to implement a single VB.NET instance of an application on a terminal server. To do this I am using code from the Flawless Code blog. It works well, except in the code is written in C# and uses an anonymous method which is not supported in VB.NET. I need to rewrite the following so that I can use it as an event in VB.NET.

static Form1 form;

static void singleInstance_ArgumentsReceived(object sender, ArgumentsReceivedEventArgs e)
    {
        if (form == null)
            return;

        Action<String[]> updateForm = arguments =>
            {
                form.WindowState = FormWindowState.Normal;
                form.OpenFiles(arguments);
            };
        form.Invoke(updateForm, (Object)e.Args); //Execute our delegate on the forms thread!
    }
}
like image 947
Skittles Avatar asked Dec 05 '25 17:12

Skittles


1 Answers

You can use this code:

Private Shared form As Form1

Private Shared Sub singleInstance_ArgumentsReceived(ByVal sender As Object, ByVal e As ArgumentsReceivedEventArgs)
    If form Is Nothing Then Return
    form.Invoke(New Action(Of String())(AddressOf updateFormMethod), e.Args)
End Sub

Private Shared Sub updateFormMethod(ByVal arguments As String())
    form.WindowState = FormWindowState.Normal
    form.OpenFiles(arguments)
End Sub
like image 99
Tereza Tomcova Avatar answered Dec 08 '25 07:12

Tereza Tomcova



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!