473,500 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# - Displaying a progressbar while executing an SQL Query.

23 New Member
Hi ,

I would like a progress bar to be displayed while running an sql query. the progress bar doesn't have to move according to the query pace - I just want it to move back and forth while the query is executing , and to disappear when the query is completed.

My problem is that the progress bar does not appear when the query is running (I'm using the data adapter fill method in order to run my queries). What can I do ?

Thanks in advance.
Oct 19 '07 #1
12 34993
Plater
7,872 Recognized Expert Expert
You just want something like "Loading..." (or "Saving...") or something?

Create a label, and tell it to be "on top" of the other controls. Then set it to invisible.
Before you run your query, set it to "visible" and do a like .Update() on the control (to make sure it updates your UI before you start the query)
Then you can run your query.
When it's done, just set the label object back to invisible
Oct 19 '07 #2
yoavyoavyoav
23 New Member
Thanks. Actually the call to the "Update" method was what I was missing. why is it required by the way ?

Thanks again.
Oct 19 '07 #3
Plater
7,872 Recognized Expert Expert
I don't have an authoritative answer to it. But, just that the "normal" GUI calls of updating don't happen when your thread is busy doing something (like executing a big sql statement). So by using the .Update() you force a "one last redraw" to happen before it becomes tied up doing other stuff.
Oct 19 '07 #4
yoavyoavyoav
23 New Member
Hi ,

Using the Update did make it appear -but during the query execution it remains static. how can I cause it to change while the query is running (I just want it to move according to my set of instruction - for eg. back and forth). ?

Thanks.
Oct 26 '07 #5
Plater
7,872 Recognized Expert Expert
Make it happen in it's own thread.
Oct 26 '07 #6
yoavyoavyoav
23 New Member
I didn't find direct instructions on how to use threading (never used it before).
All I want is to open a new thread in which the progressbar will move back and forth (I have the logic for that so that's not the issue) - and when the query is completed I want the progressbar to disappear.

I've read about Invoke , etc etc , but didn't find something that worked well.
What should I do ? thx.
Oct 29 '07 #7
Plater
7,872 Recognized Expert Expert
If you have a function that handles the moving of the "loading..." stuff, when you submit your query just create a new thread and tell it to run that function. Then when your query returns, kill that thread and set the loading screen to invisible again.
Oct 29 '07 #8
yoavyoavyoav
23 New Member
OK...so I think that doesn't really work.
I've decided to put my query running in another thread - and I want the progressbar to run while the query is running. How do I know when the query has stopped running if it's in another thread (meaning, is there some sort of a "wait for thread to finish" function ? )
Oct 29 '07 #9
Plater
7,872 Recognized Expert Expert
myThread.Join() will block the current thread until the other thread completes.
Where mythread is the Thread object for your other thread.
Oct 29 '07 #10
iqbalali
1 New Member
am doing the same thing but am stuck with the threads join?? will you help about it?
Jun 8 '10 #11
broger
2 New Member
You don't really need to join back up with the main thread, nor even wait for the spawned thread to finish. First, you'll need these methods:

Expand|Select|Wrap|Line Numbers
  1. private delegate void SetControlPropertyThreadSafeDelegate(Control control, string propertyName, object propertyValue);
  2.         public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
  3.         {
  4.             if (control.InvokeRequired)
  5.             {
  6.                 control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe),
  7.                     new object[] { control, propertyName, propertyValue });
  8.             }
  9.             else
  10.             {
  11.                 control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
  12.             }
  13.         }
  14.         private void StartProgressBar(ProgressBar pb)
  15.         {
  16.             SetControlPropertyThreadSafe(pb, "Visible", true);
  17.             SetControlPropertyThreadSafe(pb, "Style", ProgressBarStyle.Marquee);
  18.             SetControlPropertyThreadSafe(pb, "MarqueeAnimationSpeed", 100);
  19.         }
  20.         private void StopProgressBar(ProgressBar pb)
  21.         {
  22.             SetControlPropertyThreadSafe(pb, "Style", ProgressBarStyle.Blocks);
  23.             SetControlPropertyThreadSafe(pb, "MarqueeAnimationSpeed", 0);
  24.             SetControlPropertyThreadSafe(pb, "Visible", false);
  25.         }
Using this, you can set the progress bar to either be running or stopped from within your thread. Use these two calls within the threaded method to start/stop:

StartProgressBar(ProgressBar);
StopProgressBar(ProgressBar);

Generally, between those two, I do some processing, and then call Invoke(new MethodInvoker(<Method>)) to save the results of the thread to the main form. Essentially, it works by a) starting the thread, b) gathering data/perform some sort of task, c) invoking the method which uses the data that you've saved from your thread (which is threadsafe, due to Invoke()), d) finishing it up by stopping the progress bar

Hope this helps
Jul 21 '10 #12
Sfreak
64 New Member
Try using
Expand|Select|Wrap|Line Numbers
  1. Application.DoEvents();
to free your UI while you run those threads.
Jul 24 '10 #13

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

Similar topics

15
6804
by: dixie | last post by:
I have a command to open the Access Options dialogue from code: DoCmd.RunCommand acCmdOptions It also opens the Database Window behind it. Is it possible to open the Options without having...
8
19579
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied....
1
5393
by: Mehr H | last post by:
I've been trying to figure out how i can embed a Windows.Forms.ProgressBar in my webform (aspx) file. I have tried putting a Windows.Forms.ProgressBar as public on a regular winform designer form...
3
4759
by: Mitchell Vincent | last post by:
In other programming languages I've been able to easily change the style of a progress bar between smooth and blocked. I find that is either really hidden or impossible in .NET. Am I missing...
1
696
by: nobody | last post by:
Hi I'm currently developing a Windows application. At the start of the application I load several tables into datatables in a dataset. I also use a progressbar to show the user how much percent...
2
11086
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the...
4
2493
by: sivamoorthy | last post by:
how to use a progressbar in a one cpp file but defined in another header file. the function in which i am using is a static member function. how to use the progressbar inside the function ...
6
10664
by: JB | last post by:
Hi All, I have a Windows Form application that shows a "please wait" form while I query a database for various information. I display my form using Show, then run my DB query, then Close the...
10
10200
by: hsegoy1979 | last post by:
dear all iam new to sql server. I have a query. I want to display records in a new line. Iam using char(13) but it won't work. The table record contains only one field Name select * from...
0
7018
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
7397
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
5490
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,...
1
4923
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
4611
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
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
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 ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.