简体   繁体   中英

How do I convert this VB.NET invokerequired code to c#?

I inherited an old VB.NET program that was written long before I got to this job. I'm having to rewrite it in C#. I have been unable to find anything that seems to be a conversion for this. Can someone show me a translation for this in C#, please?

Private Sub Log(Message As String)

    Try

        If txtLog.InvokeRequired Then

            txtLog.Invoke(Sub()
                              Log(Message)
                          End Sub)
        Else
            txtLog.AppendText(Message & Environment.NewLine)
        End If

    Catch ex As Exception

    End Try

End Sub

This is the code converted to C# :

private void Log(string Message)
{
    try
    {
        if (txtLog.InvokeRequired == true)
        {
            txtLog.Invoke(() =>
            {
                Log(Message);
            });
        }
        else
        {
            txtLog.AppendText(Message + Environment.NewLine);
        }
    }
    catch { }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM