473,395 Members | 1,496 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,395 software developers and data experts.

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

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 34976
Plater
7,872 Expert 4TB
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
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 Expert 4TB
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
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 Expert 4TB
Make it happen in it's own thread.
Oct 26 '07 #6
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 Expert 4TB
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
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 Expert 4TB
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
am doing the same thing but am stuck with the threads join?? will you help about it?
Jun 8 '10 #11
broger
2
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
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.