0

I want to try clojure-clr

This program works fine:

(import [System])
(defn -main [& args]
 (Console/WriteLine "Hello, World!"))

but when I want to use Task class:

(import [System.Threading.Tasks])
(import [System])

(defn -main [& args]
 (Task/Delay 1))

I got error:System.InvalidOperationException: Unable to find static field: Delay

but in this case,Task/Delay is same to Console/WriteLine

I don't know why

pph
  • 48
  • 3
wang kai
  • 1,673
  • 3
  • 12
  • 21
  • `Task/Delay` accepts two arguments: https://msdn.microsoft.com/en-us/library/hh194845(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1. Could this be a cause of a problem? – OlegTheCat Feb 22 '18 at 08:38
  • Task/Delay can accept only a int arg,I have been tried in my c# program – wang kai Feb 22 '18 at 08:43

1 Answers1

2

The first one works because System is loaded by default.

Try import static:

user=> (import (System.Threading.Tasks Task))
user=> (Task/Delay 1)
#object[DelayPromise 0x1554b35 "System.Threading.Tasks.Task+DelayPromise"]

Or use fully qualified name

user=> (System.Threading.Tasks.Task/Delay (TimeSpan/FromSeconds 10))
#object[DelayPromise 0x223ef57 "System.Threading.Tasks.Task+DelayPromise"]
pph
  • 48
  • 3