Hi,

This bug was actually fixed about a month ago, which is why things didn't
quite add up for me, sorry about the confusion.

https://bugzilla.xamarin.com/show_bug.cgi?id=2483

You can work around this for now by spinning up your own thread:

Thread t = new Thread ((v) =>
{
    try {
      client.DownloadData (new System.Uri (file));
    } catch (Exception) {
      // ignore exceptions if cancelled
    }
});
t.Start ();

// when the user cancels the download
t.Interrupt ();

Best regards,
Rolf

On Tue, Apr 17, 2012 at 9:09 AM, victoria <[email protected]> wrote:

> That is odd, I can't really make it more of a test case because that's all
> there is. If I start a clean solution and a console project with just
>
>        class MainClass
>        {
>                public static void Main (string[] args)
>                 {
>                         string file =
>                        "
> http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.0.1.tar.bz2";;
>
>                          System.Net.WebClient client = new
> System.Net.WebClient();
>                         client.DownloadDataAsync(new System.Uri(file));
>                         client.CancelAsync();  // still kabooms
>                }
>        }
>
> I get the same crash. Are we using the same version? I'm on 2.10.9 (Stable)
> and I'm not really in a position where I'd feel comfortable switching to
> the
> beta branch... but if it works on beta and not stable then I guess I can
> just wait for it to be fixed, the project I'm working on isn't due for
> release for quite a while :-)
>
>
> Rolf Bjarne Kvinge wrote
> >
> > Hi,
> >
> > On Mon, Apr 16, 2012 at 10:45 AM, victoria <iminurbase@> wrote:
> >
> >> Hello list,
> >
> >
> >> I'm not sure if this is a Monotouch bug or if we're doing something
> wrong
> >> here. We're trying to use System.Net.WebClient to fetch some data async
> >> with
> >> a nice optional "Cancel this download" button for the user - however
> >> trying
> >> to cancel the request blows up everything. Behold:
> >>
> >>  // random somewhat big file to not download
> >>  string file =
> >> "http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.0.1.tar.bz2";;
> >>
> >>  WebClient client = new WebClient();
> >>  client.DownloadDataAsync(new Uri(file));
> >>  client.CancelAsync();  // kaboom
> >>
> >
> > I just tried this exact code, and it works fine for me.
> >
> > I've looked at both the exception and our WebClient implementation, and
> > the
> > exception doesn't make much sense - so something is obviously going
> wrong.
> > I suggest you file a bug with a complete test case, and I'll have a look
> > at
> > it asap.
> >
> > Rolf
> >
> >
> >>
> >> The code above works just fine on .NET/Windows - also, changing
> >> DownloadDataAsync to DownloadStringAsync seems to work as we would
> expect
> >> it
> >> to (no kaboom, but we need the raw data so unfortunately we can't use
> it)
> >>
> >> Thoughts? Bug? Help?
> >>
> >> / V
> >>
> >> --
> >> View this message in context:
> >>
> http://monotouch.2284126.n4.nabble.com/CancelAsync-on-DownloadDataAsync-crashes-monotouch-tp4560900p4560900.html
> >> Sent from the MonoTouch mailing list archive at Nabble.com.
> >> _______________________________________________
> >> MonoTouch mailing list
> >> [email protected]
> >> http://lists.ximian.com/mailman/listinfo/monotouch
> >>
> >
> > _______________________________________________
> > MonoTouch mailing list
> > [email protected]
> > http://lists.ximian.com/mailman/listinfo/monotouch
> >
>
>
> --
> View this message in context:
> http://monotouch.2284126.n4.nabble.com/CancelAsync-on-DownloadDataAsync-crashes-monotouch-tp4560900p4563814.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to