473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

HOW TO SHOW: Processing...

153 100+
There are some textboxes placed on a form along with one button.When the user presses the button a modal window pops up till the work is finished and that window shows that circling processing GIF image.
By showing the form as modal , the user will not be able to press the button again untill the shown modal window is closed, which happens automatically when the processing is done.
This I tried to achieve this effect by creating the button's click event as follows:

Futile attempt 1
{
OneForm oneform = new OneForm();
oneform.Show();// mod-less form


Thread.Sleep(); //Emulate work.Coz the Thread sleeps, the GIF icon can not animate

oneform.Close();
}

Futile attempt 2
{
OneForm oneform = new OneForm();
oneform.ShowDialog();// modal form


Thread.Sleep(); //Emulate work.GIF will animate but this line will never execute untill I close the modal form ! USELESS

}

Futile attempt 3
OneForm onefrm = new OneForm(); //oneform is a field so that I can access it from all methods
{
Thread th = new Thread(HeavyWork);
th.Start();
oneform.ShowDialog();//main thread stops here untill I close it but I satrted another thread to execute my work, thank God
}

void HeavyWork()
{
Thread.Sleep(10000);
onefrm.Close(); //OOps this is created in GUI thread so cant access/close it from any other thread
}


Futile attempt 4 //I used this coz it was doing my work, well...almost
{
Thread th = new Thread(SHowForm);
th.Start();


Thread.Sleep(10000);

th.Abort(); //work done not close the form by ending the thread
}

void ShowForm()
{
new OneForm().ShowDialog();
}

Now what happens is that the OneForm does not disappear untill I move the mouse on it.Even the dialog boxes are coming under it and when I move the mouse, it closes.

How to solve this ?

Thanks !
Sep 4 '09 #1
6 3508
GaryTexmo
1,501 Expert 1GB
Why does the thread need to sleep? Try a loop that checks whether or not your form should close with the animation in it. Put an Application.DoEvents() in that loop if you need other things to respond.

Better yet, put a timer in your form that checks when the form should close and handles it then. I'm guessing the thread.sleep is blocking everything else from happening... though I thought animated gifs took care of themselves. To be honest, this is all speculation, I've never done it before. But experiment about and let us know :)
Sep 5 '09 #2
akshaycjoshi
153 100+
Thread.Sleep() emulates some actual work.
Anyways I have found the answer.
Here is the code

Expand|Select|Wrap|Line Numbers
  1. WaitForm waitfrm = new WaitForm();
  2. delegate void del();
  3. void CLOSE()
  4. {
  5. waitfrm.Close();<br/>}
  6. private void button1_Click(object sender, EventArgs e)
  7. {
  8. Thread th = new Thread(FUNC);
  9. th.Start();
  10. waitfrm = new WaitForm();
  11. waitfrm.ShowDialog();
  12. }
  13. void FUNC()
  14. {
  15. Thread.Sleep(10000);
  16. this.Invoke(new del(CLOSE));
  17. }
Sep 5 '09 #3
if you know your form is in center of screen, you can use this comic code:
int x = Cursor.Position.X;
int y = Cursor.Position.Y;
Cursor.Position = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2);
Cursor.Position = new Point(x, y);
Sep 5 '09 #4
akshaycjoshi
153 100+
What's that for ?
:)
Sep 5 '09 #5
i had the same problem, when stopping thread the form is showing until move mouse over.
i solved it with this code after "thread.abort()", programmatically move mouse on it and move to the old position again. it's not sensible for user because speed is very high.
Sep 5 '09 #6
akshaycjoshi
153 100+
hahahaha :)
Thanks !
Sep 5 '09 #7

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

Similar topics

1
by: Billy Cormic | last post by:
Hello, Some of the functions of my web application take a good amount of time to load. Is there a good way to show users that information is processing and will enventually be loaded? Like...
4
by: Brian | last post by:
Hi there I'm not so hot on JavaScript so not sure if this can be done. I have a PHP page that runs a MySQl query, while these queries are running I would like to show a message saying...
1
by: radha | last post by:
hi friend Could somebody please tell me how to update an access record having two primary keys?(vb.net, asp.net, access Also how do we show a page from another page,for eg i am in page1.aspx and...
5
by: Anonieko | last post by:
Scenario: This is a reporting scenario where it takes a while to get back a response ( report page ) after submit. I want my user to see some kind of temporary message like 'Processing...' ...
6
by: Shawn Regan | last post by:
Hello, What is the best practice to show a window/form of some animation while processing is going on in the back ground. I want the user to see something while some processing is taking...
1
by: Pi | last post by:
I have an MDI parent with one or more children forms. Each child form has an engine thread that processes data. The child form's _Closing event is roughly 01 Private Sub...
2
by: Holysmoke | last post by:
Hi, I have a asp.net form with a button in it. In the onlclick event of button I want to write a function which does some a bit of work with a timespan of 15 seconds. So I want to show a image...
0
by: David van der kooij | last post by:
Hi, I have a webservice that returns an xmldocument. I write some processing isntructions to this xmldocument like this XmlProcessingInstruction myPI3; PItext = "progid='InfoPath.Document'";...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...

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.