ILSpy translation gives compiler error

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

ILSpy translation gives compiler error

Post by ic2 »

This compiles in C# (to set a timer calling MyMethod every 5 minutes)

Code: Select all

var timer = new System.Threading.Timer(
    e => MyMethod(),  
    null, 
    TimeSpan.Zero, 
    TimeSpan.FromMinutes(5));

ILSpy translates that to:

Code: Select all

	Timer{dueTime: TimeSpan.Zero, period: TimeSpan.FromMinutes(5.0), Callback: { =>Self:MyMethod()	}, state: null}
	Close()

This gives the following compiler eror:

Error XS9002 Parser: unexpected input '{'

1 What is wrong?
2 I I assume it needs to be fixed in the ILSpy plugin?

Dick
User avatar
Chris
Posts: 4907
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

ILSpy translation gives compiler error

Post by Chris »

Hi Dick,

Indeed, that's not the correct translation. In X# syntax, the equivalent is:

Code: Select all

VAR timer := System.Threading.Timer{;
    MyMethod,;
    NULL,;
    TimeSpan.Zero,;
    TimeSpan.FromMinutes(5)}
and of course you also need to have a method (or function) defined that will be called when the timer ticks:

Code: Select all

METHOD MyMethod(state AS OBJECT) AS VOID
.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply