Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

RichTextBox and other controls wont update

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Afshar Mohebbi - 26 Jun 2007 12:12 GMT
Hi everyone,

I have a loop that runs thousands of time an does IO operations. in
each loop I update RichTextBox.Text but it does not take effect until
the end of whole loop. It occurs about other controls too. How can I
enforce these controls to be updated correctly?

I'm using:
VS 2005,
C#,
framework 2.0
Nhibernate

Thanks in Advance:
Afshar Mohebbi
KK - 25 Jun 2007 22:45 GMT
this is a standard behaviour in the sense that your long running operation
is on the UI thread and its blocking the UI thread. So untill all is over,
it wont update anythig. As mentioned in other reply, think of
Application.DoEvents or better if you can implement these things in separate
threads.

> Hi everyone,
>
[quoted text clipped - 11 lines]
> Thanks in Advance:
> Afshar Mohebbi
Afshar Mohebbi - 27 Jun 2007 09:19 GMT
Dear Friends,

I tried Application.DoEvents() and it worked fine. But it is very
slow. Is there a better way? What is "some state-object"? follwoing is
my complete code:

       private Hashtable ImportOrganization(string sheetName,
ExcelUtility excelUtility)
       {
           Hashtable result = new Hashtable();

           const int nameCol = 1;
           const int orgIdCol = 2;
           const int telCol = 3;
           const int faxCol = 4;
           const int addressCol = 5;

           excelUtility.LoadWorksheet(sheetName);
           int rowIndex = startingRow;
           string rowIdentifier = excelUtility.ReadCell(rowIndex,
startingCol);
           while (!String.IsNullOrEmpty(rowIdentifier))
           {
               Global.AddMessage(rtbCount, rowIndex);
               Faraconesh.BusinessFramework.Common.Organization
organization = new Faraconesh.BusinessFramework.Common.Organization();
               organization.Name = excelUtility.ReadCell(rowIndex,
startingCol + nameCol);
               organization.OrgId = excelUtility.ReadCell(rowIndex,
startingCol + orgIdCol);
               organization.Tel = excelUtility.ReadCell(rowIndex,
startingCol + telCol);
               organization.Fax = excelUtility.ReadCell(rowIndex,
startingCol + faxCol);
               organization.Address = excelUtility.ReadCell(rowIndex,
startingCol + addressCol);

               if (result.ContainsKey(rowIdentifier))
                   throw new Exception("duplicate row number");
               else
               {
                   organization.RuntimeState =
Faraconesh.ApplicationFramework.Common.RuntimeState.Added;

Faraconesh.BusinessFramework.Common.CommonService.Instance.UpdateOrganization(organization);
                   result.Add(rowIdentifier, organization);
               }
               rowIdentifier = excelUtility.ReadCell(++rowIndex,
startingCol);
               Application.DoEvents();
           }
           return result;
       }

       internal static void AddMessage(RichTextBox rtb, int intParam)
       {
           AddMessage(rtb, intParam.ToString());
       }

       internal static void AddMessage(RichTextBox rtb, string
stringParam)
       {
           const int maxLength = 4;
           rtb.Text += stringParam + "\n";
           if (rtb.Lines.Length > maxLength)
           {
               string[] oldLines = rtb.Lines;
               string[] newLines = new string[maxLength];
               for (int i = 0; i < maxLength; i++)
                   newLines[i] = oldLines[i + 1];
               rtb.Lines = newLines;
           }
       }
   }

thanks,
afshar
Jeff Gaines - 26 Jun 2007 12:40 GMT
On 26/06/2007 in message

>Hi everyone,
>
[quoted text clipped - 11 lines]
>Thanks in Advance:
>Afshar Mohebbi

Try Application.DoEvents() in the loop - it may slow it down though.

Signature

Jeff Gaines

Alex Meleta - 26 Jun 2007 12:47 GMT
Hi Afshar,

Can you provide peace of code?

Anyway it's a bad idea to write into controls every iteration step. Better
soultion is to create some state-object to store iterations data and reflect
changes to presentation level afterward. You will control execution in one
place and improve perfomance, because you should know about rendering if
visible modification occurs.

Kind Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com

AM> Hi everyone,
AM>
AM> I have a loop that runs thousands of time an does IO operations. in
AM> each loop I update RichTextBox.Text but it does not take effect
AM> until the end of whole loop. It occurs about other controls too. How
AM> can I enforce these controls to be updated correctly?
AM>
AM> I'm using:
AM> VS 2005,
AM> C#,
AM> framework 2.0
AM> Nhibernate
AM> Thanks in Advance:
AM> Afshar Mohebb

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.