.NETGURU
Textbox updates in single-thread app
Messages   Related Types
This message was discovered on microsoft.public.dotnet.general.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

JohnReb (VIP)
I have a C#.NET app that is (currently) single-threaded. At one stage it may
have to process a large amount of data, which can take a few minutes.

To keep the user panic level down, the app displays updates in a TextBox
that shows it is making progress. This is all fine unless the app loses focus
- for instance if the user switches to IE or something while the lengthy
processing is going on.

Once the app loses focus, the TextBox updates no longer appear, and the
TaskManager reports the app is not responding. When the lengthy processing is
complete, all TextBox updates appear at once.

After each TextBox update, calls to Invalidate () and Update () are made.

Since the app is single-threaded and the processing is an atomic operation,
there is no accommodation for passing control back out to the .NET framework,
other than the Invalidate and Update calls.

Am I doing something dumb (a definite possibility :) ), or is the only
viable solution to go to a multi-thread approach, or break the atomic nature
of the processing?

Any ideas will be most appreciated.

Best Regards,
John
Reply to this message...
 
    
Imran Koradia (VIP)
Are you using a loop for the data processing? If so, you might want to add
Application.DoEvents within the loop. This will give the form and its
controls a chance to update themselves.

Imran.

"JohnReb" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I have a C#.NET app that is (currently) single-threaded. At one stage it
may
[Original message clipped]

Reply to this message...
 
    
Jon Skeet [C# MVP] (VIP)
Imran Koradia <Click here to reveal e-mail address> wrote:
[Original message clipped]

This should definitely only be an interim measure, however.
Application.DoEvents() is basically a hack to simulate multi-threading,
and it leads to other problems (such as re-entrancy).

Calling Update() on the relevant control would also work, I believe.

For the OP:
See http://www.pobox.com/~skeet/csharp/threads/" target="_blank">http://www.pobox.com/~skeet/csharp/threads/ for general .NET
threading stuff.

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
 
    
JohnReb (VIP)
Wow! Thanks! The multi-thread approach will I think be a 'better' ultimate
solution, but this works just great for the short term!

I appreciate the help...

Best Regards,
John

"Imran Koradia" wrote:

[Original message clipped]

Reply to this message...
 
    
Imran Koradia (VIP)
[Original message clipped]

hth (happy to help) :)

Reply to this message...
 
    
Henk Verhoeven
HI John

if you use the LblName.Refresh() method, then it will repaint the label ,
but some parts of the form may still not repaint.

Why don't you try using this simple thread implementation, it works really
well and it is easy to implement.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms08162002.asp

Drop me a private e-mail and I will send you some sample code :-)

Henk
"JohnReb" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
JohnReb (VIP)
Hi Henk -

Many thanks... sadly, though, this looks like it pretty much confirms my
fear... multi-thread is the solution.

Due to circumstances beyond my control, this will change will be delayed for
several weeks at least...

I may very well contact you again when I get into it. I've done lots of
multi-thread stuff before, but not in C#.NET yet.

I appreciate your help...

Best Regards,
John

"Henk Verhoeven" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.TextBox
System.Windows.Forms.Application
System.Windows.Forms.TextBox




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification