Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

ILSpy translation gives compiler error 23 Feb 2023 21:59 #25360

  • ic2
  • ic2's Avatar
  • Topic Author


  • Posts: 1667
  • This compiles in C# (to set a timer calling MyMethod every 5 minutes)
    var timer = new System.Threading.Timer(
        e => MyMethod(),  
        null, 
        TimeSpan.Zero, 
        TimeSpan.FromMinutes(5));
    

    ILSpy translates that to:

    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

    Please Log in or Create an account to join the conversation.

    ILSpy translation gives compiler error 24 Feb 2023 01:35 #25361

    • Chris
    • Chris's Avatar


  • Posts: 3981
  • Hi Dick,

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

    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:

    METHOD MyMethod(state AS OBJECT) AS VOID

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.
    • Page:
    • 1