Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com