Bonjour Omar.
L'erreur subsiste en version 17.6.8 (build 400). Le message d'erreur concernant la ligne 37 est précisément : The type or namespace name 'MethodInvoker' could not be found (are you missing a using directive or an assembly reference?) (CS0246).
Voici le code d'une application cocoa très simple qui reproduit l'erreur :
using AppKit;
using CoreGraphics;
using System;
using System.Threading.Tasks;
namespace TestMethodInvoker
{
public partial class ViewController : NSViewController
{
private NSButton btnUpdate;
private NSTextField labelResult;
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Do any additional setup after loading the view.
btnUpdate = new NSButton(new CGRect(10, 200, 100, 23));
View.AddSubview(btnUpdate);
btnUpdate.Title = "Run";
btnUpdate.Activated += btnUpdate_Click;
labelResult = new NSTextField(new CGRect(120, 200, 200, 23));
View.AddSubview(labelResult);
labelResult.StringValue = "Valeur initiale";
}
private void btnUpdate_Click(object sender, EventArgs e)
{
Task.Run(() =>
{
string text = "Updated from another thread";
this.Invoke((MethodInvoker)delegate
{
labelResult.Text = text;
});
});
}
}
}
Cordialement,
Gilbert