> But even if he does it in a background worker thread, the documentation and
> examples on MSDN call DoEvents to make sure the UI is still operable.
>
> So I think he should just try using DoEvents and see if it fixes the
> problem, and if it does, fine.
If you're not blocking the UI thread, there should be no need to call
DoEvents at all. Could you give an example of such documentation?
Threading issues should not be solved by just trying something - it's
too easy to end up with code which will work *most* of the time. You
know - until a customer ends up with it...

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
RobinS - 15 Mar 2007 19:56 GMT
>> But even if he does it in a background worker thread, the documentation
>> and
[quoted text clipped - 9 lines]
> too easy to end up with code which will work *most* of the time. You
> know - until a customer ends up with it...
Well, this is the article I was thinking of, but you're right, it doesn't
say anything about DoEvents.
http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
I seem to vaguely remember that when I implemented my version of this, if I
didn't put a DoEvents in, my UI was nonresponsive, maybe my Cancel button
didn't work or something like that. I'll try taking it out and see what it
does.
One thing that was interesting about it. If I have it in there, I can not
kick off my background worker as a function
e.Result = ExcelExport.testProgressing(100, worker, e)
This will cause an exception. But I can run it this way:
ExcelExport.testProgressing(100, worker, e)
Interesting.
Robin S.
Jon Skeet [C# MVP] - 15 Mar 2007 20:47 GMT
> One thing that was interesting about it. If I have it in there, I can not
> kick off my background worker as a function
[quoted text clipped - 4 lines]
>
> ExcelExport.testProgressing(100, worker, e)
You mean that just assigning to e.Result is causing an exception? What
is "e" in this case?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
RobinS - 19 Mar 2007 00:51 GMT
e is the ProcessChangedEventArgs.
I went back and looked at the code again, and tried the line before again,
and now it doesn't have any problem at all, whether I have DoEvents in
there or not. And the DoEvents no longer seems necessary either. (insert
Twilight Zone music here).
The only thing I changed was I was mucking around with OOP and changed the
class from a static class to a non-static class so you have to instantiate
it. I really think it should be a static class, because all it does it
create a report, and they can not run more than one simultaneously, but I
was mucking around.
I'm going to change it back to a static class and see if it makes any
difference.
Maybe I inadvertently fixed it somehow. It was my first foray into
threading and I was going back and forth trying different things.
I'll report back.
Robin S.
------------------------------
>> One thing that was interesting about it. If I have it in there, I can
>> not
[quoted text clipped - 8 lines]
> You mean that just assigning to e.Result is causing an exception? What
> is "e" in this case?