Weird SwingWorker Bug HELP! - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: Weird SwingWorker Bug HELP!

  1. #16
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Weird SwingWorker Bug HELP!

    Whats interesting is that setProgress is supposed to throw IllegalArgumentException when it gets a value outside the 0-100 range. And adding a try, catch around your getData method does show the exception, but without that, the exception disappears into nothingness. I started tracing into the SwingWorker source, made it as far as FutureTask.Sync.innerSetException, then gave up. The disappearing exception might be a SwingWorker bug.

  2. #17
    Join Date
    Aug 2011
    Posts
    13

    Re: Weird SwingWorker Bug HELP!

    Yeah.... From what I can see.... I think setProgress(100 or 101) calls done() for some reason... I think thats at least one of my problems.... The math.min helped a little too...

    Thanks for everything man

  3. #18
    Join Date
    Aug 2011
    Posts
    13

    Re: Weird SwingWorker Bug HELP!

    I should've tried this before, but after completely removing setProgress(), everything works fine.

    So I then moved the setProgress out of the inner for loop so it just checks with the width to make things simpler. Then I made another check to make sure newProgress > 0 && newProgress < 100 && newProgress != getProgress() before setting the progress. This works flawlessly.

    I've kinda concluded that SwingWorker is a very touchy class that needs much more documentation and transparency.

  4. #19
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Weird SwingWorker Bug HELP!

    At least in the SSCCE you posted, the only problem was passing a value outside the 0-100 range to setProgress. Check the setProgress docs & you'll see it expects the parameter to be 0-100 & will throw an IllegalArgumentException otherwise. The problem is that SwingWorker swallows exceptions in certain cases. This seems to be a known issue:

    http://www.google.com/search?q=Swing...ows+exceptions

    For the SSCCE, the only change required was ensuring not to pass > 100 to setProgress. But if you want to continue to use SwingWorker, I'd suggest also explicitly adding a try,catch(Exception) clause around the entire doInBackground code to avoid any exceptions being swallowed. Either that or use one of the solutions in the google link I posted (I haven't read them though).

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center