Пример #1
0
    /// <summary>
    /// Parallel.ss contains a "test" function that evaluates three expressions in parallel, using the "parallel" primitive.
    /// Each one sleeps asynchronously 100 milliseconds before finishing.
    /// So at first the evaluation is not completed.  
    /// After the wait, they all should be completed.  
    /// The result of the test function is a list of the completion results of the three evaluations.
    /// This illustrates retrieving the async result after completion.
    /// </summary>
    public static void Main()
    {
        interp = Interpreter.New(new[] { "parallel.ss" });

        var startTime = DateTime.Now;
        IAsyncResult res = interp.BeginEval(interp.Read("(test)"), null, null);
        Console.WriteLine("Completed: {0}", res.IsCompleted);
        res.AsyncWaitHandle.WaitOne();
        Console.WriteLine("Completed: {0} in {1} ms", res.IsCompleted, (DateTime.Now - startTime).Milliseconds);
        Console.WriteLine("Result: {0}", ((AsyncResult<SchemeObject>)res).Result);
        Console.ReadLine();
    }
Пример #2
0
    private static bool isComplete; // = false;

    #endregion Fields

    #region Methods

    /// <summary>
    /// Async.ss uses System.Net.WebRequest to (asynchronously) fetch a web page (in the function get-content).
    /// Since it is asynchronous, it has not completed when the evaluation returns.
    /// After completion, the callback ShowResult is called, which displays the page contents.
    /// This allows the main method to proceed.
    /// While it is executing, get-content displays the number of bytes in each read that it does.
    /// </summary>
    public static void Main()
    {
        interp = Interpreter.New(new[] { "async.ss" });
        IAsyncResult res = interp.BeginEval(interp.Read(@"(get-content ""http://microsoft.com"")"), ShowResult, null);
        Console.WriteLine("Completed: {0}", res.IsCompleted);
        while (isComplete == false)
        {
            Thread.Sleep(100);
        }

        Console.WriteLine("Completed: {0}", res.IsCompleted);
        Console.ReadLine();
    }