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

TOPIC:

How does this translate C#->X# 27 Sep 2022 23:21 #24032

  • ic2
  • ic2's Avatar
  • Topic Author


  • Posts: 1555
  • This C# code:

    public static void ProcessUITasks()
    	// When called, forces the UI to redraw. 
    	{
    		DispatcherFrame frame = new DispatcherFrame();
    		Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate (object parameter) {
    			frame.Continue = false;
    			return null;
    		}), null);
    		Dispatcher.PushFrame(frame);
    	}

    in ILSpy translates as:
    public static method ProcessUITasks() as void
    	local frame as DispatcherFrame
    	frame := DispatcherFrame{}
    	Dispatcher.CurrentDispatcher:BeginInvoke(DispatcherPriority.Background, (DispatcherOperationCallback){ =>
    		frame:Continue := false
    		return null
    	}, null)
    	Dispatcher.PushFrame(frame)

    This gives Error XS1593 Delegate 'System.Windows.Threading.DispatcherOperationCallback' does not take 0 arguments

    Indeed delegate (object parameter) from the C# code is missing. But I am not sure how to do this in X#

    Anyone an idea?

    Dick

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

    How does this translate C#->X# 28 Sep 2022 07:54 #24040

    • Chris
    • Chris's Avatar


  • Posts: 3667
  • Hi Dick,

    This should do it, by supplying the parameter as the c# version of the code does:

    Dispatcher.CurrentDispatcher:BeginInvoke(DispatcherPriority.Background, (DispatcherOperationCallback){ parameter AS OBJECT =>
    		frame:Continue := FALSE
    		RETURN NULL
    	}, NULL)
    XSharp Development Team
    chris(at)xsharp.eu

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

    How does this translate C#->X# 28 Sep 2022 20:54 #24056

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1555
  • Hello Chris,

    Thanks, it works now.

    I must confess that I have no idea how the syntax is supposed to work; any Lambda expressions or "delegates" in my program are "borrowed" and even now I see your working X# solution I do not understand how you got to this (gone is the delegate, added is the =>).

    But main thing is that it works!

    Dick

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

    How does this translate C#->X# 28 Sep 2022 22:42 #24059

    • robert
    • robert's Avatar


  • Posts: 3213
  • Dick,

    There are 2 ways to write this:
    - A Lambda expression (with the => operator, like you did)
    - With the DELEGATE keyword
    Dispatcher.CurrentDispatcher:BeginInvoke(DispatcherPriority.Background, (DispatcherOperationCallback){ DELEGATE ( p AS OBJECT )  {  frame:Continue := FALSE, NULL }, NULL)

    The syntax for the DELEGATE expression is
    DELEGATE [ ( Parameters) ] { <Block> }
    Where <Block> is :
    - a single expression
    - an expression list, seperated with commas. The last expression is the return value, like above. All on one line.
    - a statement block (starts with a CRLF after the LCurly ({) and also has a CRLF before the RCurly (})
    XSharp Development Team
    The Netherlands

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

    • Page:
    • 1