473,466 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with Window Form In C#

2 New Member
I created a form cosists of some controls
when i press the action control button a some sort of loop occur and take
some time to finish (about 3 minutes)

the problem occur when i select another program and comeback to my application,my form showed as white until the process finished

is it any way to refresh !!!

help is very appreciated :-)
Jul 15 '08 #1
5 924
Plater
7,872 Recognized Expert Expert
Inside your loop, call Application.DoEvents()
Jul 15 '08 #2
SOB7ANALLAH
2 New Member
Thank you very much plater
the application work now very well
Jul 16 '08 #3
IanWright
179 New Member
Inside your loop, call Application.DoEvents()
Plater, is that a preferred method of solving those problem with GUI updates?

I've not known about that method before and always handled any operations that were going to take a considerable amount of time by firing off another thread, then using delegate to update controls... but that approach looks much easier... I'm just wondering about the benefits/drawbacks of either approach.

I'd normally do something along the following lines, and enable various buttons etc when a progress bar hits 100%. Just used a label here for simplicity...

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void button_click(object sender, EventArgs e)
  3. {
  4.    Thread t = new Thread(new ThreadStart(DoStuff));
  5.    t.Start();
  6. }
  7.  
  8. private void DoStuff()
  9. {
  10.    int i = 0;
  11.    While(i < 10000000)
  12.    {
  13.      i++;
  14.      UpdateText(i);
  15.    }
  16. }
  17.  
  18. delegate void UpdateDelegate(int i);
  19. private void UpdateText(int i)
  20. {
  21.    if(label1.InvokeRequired)
  22.    {
  23.       UpdateDelegate ud = new UpdateDelegate(UpdateText);
  24.       this.Invoke(ud, new object[] { i });
  25.    }
  26.    else
  27.    {
  28.       label1.Text = i.ToString();
  29.    }
  30. }
  31.  
  32.  
Jul 16 '08 #4
Plater
7,872 Recognized Expert Expert
Application.DoEvents() just instructs the program to process any windows messages it has received.
While using threads and delegates is probably the prefered method, it works in smaller situtations where threads would be overkill
Jul 16 '08 #5
IanWright
179 New Member
Ok, thanks for that Plater
Jul 16 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Federico Bari | last post by:
Good morning all from italy, i have probably a compatibility problem with a html/javascript page. The aim of the code of the file test.htm you find here following (copy the 3 files in the...
6
by: Shaun Fleming | last post by:
I've been trying to make this simple script compatible across various browsers. It works for IE 6.0 and NS 7 but doesnt work with Opera (I have version 7.11). This is what is supposed to happen:...
8
by: rdlebreton | last post by:
Hi, Folks! I've been trying to develop my own version of these draggable layers and I have been limiting myself to IE6...for now. I have looked at some other examples to get ideas of creating...
3
by: Tyrone Slothrop | last post by:
The first question, is this even possible? What I need to do is pass the contents of a PHP web page from a textarea using window.open method to a new browser window and display it. The page has...
7
by: Mike | last post by:
Hi! I posted this question in browser_ctl group as well but got no results. I have a form with embedded WebBrowser. Upon clicking on a link in the embedded webbrowser that calls JavaScript's...
3
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent...
14
by: Christian Kaiser | last post by:
We have a component that has no window. Well, no window in managed code - it uses a DLL which itself uses a window, and this is our problem! When the garbage collector runs and removes our...
5
by: Steve | last post by:
Hi, I currently have a problem passing a variable value from one page to another. Once a form submit button is pressed java pops up a window and displays some information. The problem being is...
2
by: Mux | last post by:
I am facing the following problem while exporting data to Word. The current implementation is as described below: I have a JSP file which has a link that enables you to export the data to Word....
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.