İngilizce dilinde oku

Aracılığıyla paylaş


MethodInvoker Temsilci

Tanım

Void olarak bildirilen ve parametre içermeyen yönetilen kodda herhangi bir yöntemi yürütebilen bir temsilciyi temsil eder.

C#
public delegate void MethodInvoker();

Örnekler

Aşağıdaki kod örneği, uygulama formunun başlık çubuğunu güncelleştiren bir yöntemi çağırmak için nasıl kullanılacağını MethodInvoker gösterir.

C#
public partial class Form1 : Form
{
    public Form1()
    {
        // Create a timer that will call the ShowTime method every second.
        var timer = new System.Threading.Timer(ShowTime, null, 0, 1000);           
    }

    private void ShowTime(object x)
    {
        // Don't do anything if the form's handle hasn't been created 
        // or the form has been disposed.
        if (!this.IsHandleCreated || this.IsDisposed) return;
        
        // Invoke an anonymous method on the thread of the form.
        this.Invoke((MethodInvoker) delegate
        {
            // Show the current time in the form's title bar.
            this.Text = DateTime.Now.ToLongTimeString();
        });
    }
}

Açıklamalar

MethodInvoker void parametre listesiyle bir yöntemi çağırmak için kullanılan basit bir temsilci sağlar. Bu temsilci, denetimin Invoke yöntemine çağrı yaparken veya basit bir temsilciye ihtiyacınız olduğunda ancak kendiniz tanımlamak istemediğinizde kullanılabilir.

Uzantı Metotları

GetMethodInfo(Delegate)

Belirtilen temsilci tarafından temsil edilen yöntemi temsil eden bir nesnesi alır.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9