[Mono-dev] Task class usage problem

Jérémie Laval jeremie.laval at gmail.com
Mon Mar 21 07:40:48 EDT 2011


Hello,

This is a bug in our implementation. Could you fill a bug please?

--
Jérémie Laval
http://neteril.org

On Mon, Mar 21, 2011 at 11:37 AM, vart <artemyv at gmail.com> wrote:

> I'm compiling the following code on VS2010 or Monodev 2.6 for windows with
> Net4.0 settings and get the correct output
>
> I compile the same code on Ubuntu/OpenSUSE using Mono 2.10 and Monodev 2.6
> beta1 - I got not output.
>
> What is the problem here?
>
>
> static void Main()
>    {
>
>        var parent = Task.Factory.StartNew(() =>
>        {
>            // We’ll throw 3 exceptions at once using 3 child tasks:
>
>            int[] numbers = { 0 };
>
>            var childFactory = new TaskFactory
>             (TaskCreationOptions.AttachedToParent,
> TaskContinuationOptions.None);
>
>            childFactory.StartNew(() => 5 / numbers[0]);   // Division by
> zero
>            childFactory.StartNew(() => numbers[1]);      // Index out of
> range
>            childFactory.StartNew(() => { throw null; });  // Null reference
>        });
>
>        try { parent.Wait(); }
>        catch (AggregateException aex)
>        {
>            aex.Flatten().Handle(ex =>   // Note that we still need to call
> Flatten
>            {
>                if (ex is DivideByZeroException)
>                {
>                    Console.WriteLine("Divide by zero");
>                    return true;                           // This exception
> is "handled"
>                }
>                else if (ex is IndexOutOfRangeException)
>                {
>                    Console.WriteLine("Index out of range");
>                    return true;                           // This exception
> is "handled"
>                }
>                else
>                {
>                    Console.WriteLine("Other exception: " + ex.Message);
>                    return true;                           // This exception
> is "handled"
>                }
>                //return false;    // All other exceptions will get rethrown
>            });
>        }
>    }
>
>
> Output on Windows
>
> Other exception: Object reference not set to an instance of an object.
> Divide by zero
> Index out of range
>
> These line could be shown in different order depending on Task execution
> order.
>
> On linux I do not get any output.
> Same problem with several other samples using Task/TaskFactory classes from
> System.Threading.Tasks namespace
>
>
>
> --
> View this message in context:
> http://mono.1490590.n4.nabble.com/Task-class-usage-problem-tp3393138p3393138.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110321/6b27aa81/attachment.html 


More information about the Mono-devel-list mailing list