Question

progress bars with timer not working c#

Asked by: flynny

hi all,

i've added a progress bar to a form. no i have a static class for handling all my sql login etc.

in the sql login method i add a time out of 24 seconds, now i want to show progress (rather than appering to hang) for my program logging in.
i have created a timer for handling the event, and it is working however it doesnt seem to be working in the seperate thread.

the code seems to hang and then after the time out accurs shoots up. am i doing somehting wrong?

private void Next_Button_Click(object sender, EventArgs e)
        {
            Progress_Bar.Visible = true;
            Progress_Bar.Minimum = 0;
            Progress_Bar.Maximum = 24;
            Progress_Bar.Step = 1;
            Progress_Bar.Value = 0;
            timer1.Enabled = true;
            
            //call the check server method to continue
            if (Test_Server())
            {
                NewPage2 form = new NewPage2();
                form.Show();
                close_dialog = true;
                this.Close();
            }
 
            Progress_Bar.Value = 24;
        }
 
the test_server method is basically just calling this method in my static class
 
      //Here is where I create my connection.
        private static SqlConnection createConn()
        {
            //Here you have your connection string you can edit it here.
            //need to check if we have a DSN or not.
            //also need to add username and password
            string mySqlConnectionString = buildConnString();
            
            //If you wish to use SQL security, well just make your own connection string...
            //I make sure I have declare what mySqlConnection stand for.
            if (mySqlConnection == null) { mySqlConnection = new SqlConnection(); };
 
            // Since i will be reusing the connection I will try this it the connection dose not exist.
            if (mySqlConnection.ConnectionString == string.Empty || mySqlConnection.ConnectionString == null)
            {
                // I use a try catch statement cuz I use 2 set of arguments to connect to the database
                try
                {
                    //First I try with a pool of 5-40 and a connection time out of 4 seconds. then I open the connection.
                    mySqlConnection.ConnectionString = "Min Pool Size=5;Max Pool Size=40;Connect Timeout=4;" + mySqlConnectionString + ";";
                    mySqlConnection.Open();
                }
                catch (Exception)
                {
                    try
                    {
                        //If it did not work i try not using the pool and I give it a 45 seconds timeout.
                        if (mySqlConnection.State != ConnectionState.Closed)
                        {
                            mySqlConnection.Close();
                        }
                        //changed the timeout from 40s to 20s as too long to wait.
                        mySqlConnection.ConnectionString = "Pooling=false;Connect Timeout=20;" + mySqlConnectionString + ";";
                        mySqlConnection.Open();
                    }
                    catch (Exception e)
                    {
                        CustomMessage customMessage = new CustomMessage();
 
                        //parse the exception to find out what went wrong and relay it back.
                        if (e.Message.Contains("Login failed for user"))
                            throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, e.InnerException, customMessage.GetString("Login"));
                        else if(e.Message.Contains("network-related"))
                            throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, e.InnerException, customMessage.GetString("DSN"));
                        else
                            throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, e.InnerException, customMessage.GetString("Unknown"));
                    }
                }
                return mySqlConnection;
            }
            //Here if the connection exsist and is open i try this.
            if (mySqlConnection.State != ConnectionState.Open)
            {
                try
                {
                    mySqlConnection.ConnectionString = "Min Pool Size=5;Max Pool Size=40;Connect Timeout=4;" + mySqlConnectionString + ";";
                    mySqlConnection.Open();
                }
                catch (Exception)
                {
                    try
                    {
                        if (mySqlConnection.State != ConnectionState.Closed)
                        {
                            mySqlConnection.Close();
                        }
                        mySqlConnection.ConnectionString = "Pooling=false;Connect Timeout=45;" + mySqlConnectionString + ";";
                        mySqlConnection.Open();
                    }
                    catch (Exception e)
                    {
                        CustomMessage customMessage = new CustomMessage();
 
                        //parse the exception to find out what went wrong and relay it back.
                        if (e.Message.Contains("Login failed for user"))
                            throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, e.InnerException, customMessage.GetString("Login"));
                        else if (e.Message.Contains("network-related"))
                            throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, e.InnerException, customMessage.GetString("DSN"));
                        else
                            throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, e.InnerException, customMessage.GetString("Unknown"));
                    }
                }
            }
            return mySqlConnection;
        }
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-11 at 09:32:52ID24725114
Topic

C# Programming Language

Participating Experts
3
Points
500
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. timers
    I need to run v:\setup.exe/q and have a timer showing for 3 minutes-- Setup.exe is a virus update that we run, and it runs everytime a pc boots up on our network. My problem is that I set it up in a batch file and the setup runs for 2 mins - the user can't use their compu...
  2. timer
    Hi, im designing a mobile phone simulation, does anyone know how i can add a clock timer (counting progressively) im sure i will have to use the TIMER component, its job will basically be to record the total time a call in connected. ive basically got to the point where y...
  3. VB6 using progress bar with timer control
    I have a splash screen that loads (form1) and it contains a timer control (timer1) and and progress bar (progressbar1). I want to set the timer control to 5 seconds and have the progress bar increment each second that the timer is counting. Once the timer is complete, it wi...
  4. Figuring out Timer Interval for Progress Bar
    I'm having a really hard time wrapping my brain around this one. I have a button, a timer, and a progress bar. Dim L As Label TotalTime = "0" 'set the variable that tracks the total required time to 0 For i = 1 To 5 Set L = Form1("Liq" & i & ...
  5. Timers & Progress Bars
    Hello- I am writing a simple application with three progress bars...(I have added a timer to my form also) ProgressBar1 counts tenths of a second... ProgressBar2 counts seconds... and ProgressBar3 counts minutes... or at least that's what I want it to do... I want ProgressB...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jungesPosted on 2009-09-12 at 11:41:25ID: 25317438

on you separate thread you have to call the Progress_Bar.Invoke method for all  operations that interacts with the UI thread

 

by: flynnyPosted on 2009-09-12 at 12:32:40ID: 25317596

hi

thanks for your reply is the timer not running in a seperate thread anyway?

sorry can you elaborate on what you mean please? do i have to create a specific thread for the timer?

many thanks,

Matt.

 

by: jungesPosted on 2009-09-14 at 05:27:29ID: 25324696

The timer is owned by UI thread.


//
public delegate void myMethodDelegate( int val );

public void update(int val){
   Progress_Bar.Value = val;
}


// on you thread you can call
this.Invoke(new myMethodDelegate( update, new object[]{24} ));

 

by: flynnyPosted on 2009-09-16 at 09:35:12ID: 25347469

sorry can you explain this further please. Do you mean in the timer tick method?

thanks,

Matt.

 

by: flynnyPosted on 2009-09-17 at 09:08:27ID: 25357744

hi i removed the timer and used

system.threading.

however because i am trying to update the progress of the bar in a seperate thread i get the following exception. any ideas on how i get around this?

i did read about the backgroundworker class. would you recommend using this over threading?

matt.

       private void tick(object sender, EventArgs e)
        {
            Progress_Bar.PerformStep();
        }
 
            System.Timers.Timer timer = new System.Timers.Timer(); 
            timer.Interval = 1000; 
            timer.Elapsed += new System.Timers.ElapsedEventHandler(tick); 
            timer.Start();
 
            Progress_Bar.Visible = true;
            Progress_Bar.Minimum = 0;
            Progress_Bar.Maximum = 24;
            Progress_Bar.Step = 1;
            Progress_Bar.Value = 0

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: flynnyPosted on 2009-09-18 at 05:33:31ID: 25365203

hi,

i've used a backgroundworker to run this however the same problem is happening with the hanging until the method has completed the time out. any ideas why? please find the code attached.

many thanks,

matt.

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
                for (int i = 0; i < 24; i++)   
                {   
                    System.Threading.Thread.Sleep(1000); //do some intense task here.   
                    backgroundWorker1.ReportProgress(i*(100/24)); //notify progress to main thread. We also pass time information in UserState to cover this property in the example.   
 
                    //if cancellation is pending, cancel work.   
                    if (backgroundWorker1.CancellationPending)   
                    {   
                        e.Cancel = true;    
                        return;   
                    }   
                } 
        }
 
//i invoke as follows
 
            Progress_Bar.Visible = true;
            Progress_Bar.Minimum = 0;
            Progress_Bar.Maximum = 100;
            Progress_Bar.Value = 0;
            backgroundWorker1.RunWorkerAsync();

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:

Select allOpen in new window

 

by: flynnyPosted on 2009-09-18 at 05:34:13ID: 25365208

sorry forgot to include this method too.

       private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)   
        {   
            Progress_Bar.Value = e.ProgressPercentage; //update progress bar   
        } 

                                              
1:
2:
3:
4:

Select allOpen in new window

 

by: itsmeandnobodyelsePosted on 2009-09-21 at 19:57:15ID: 25389280

>>>> is the timer not running in a seperate thread anyway?
>>>> sorry can you elaborate on what you mean please? do i have to create a specific thread for the timer?

I have no experience with managed C++ or C# but perhaps I can put some light to the timers and the threading.

Your dialog runs in that what junges called the UI thread. Normally, it is the main and only thread. That UI thread permanently is running in a loop which looks like (pseudo code)

   while (PeekMessage(mainWnd, Message))
   {
         GetMessage(mainWnd, Message);
         TranslateMessage(mainWnd, Message);
         DispatchMessage(mainWnd, Message);
   }

In the DispatchMessage all handlers will be called that are provided by your classes  or by system classes . Those handlers will post (set at end) or send (set at front) new messages to this so-called message pump, what keeps the system running. The loop ends when a WM_QUIT message was processed and then the UI thread (and normally) the process could end as well.

Given that message loop, there are two ways in Windows how to implement a timer.

(1) Performing a timer in the UI thread by using the message loop

Here no further thread is involved but handled by the message queue itself. After a timer was installed a WM_TIMER message was fired when the time has expired. You handle the timer message in a handler function like OnTimer.

Note, the WM_TIMER is a low priority message. It only was retrieved (and dispatched) in message queue if not higher priority messages were to process.

Another note: when OnTimer was called you are in the main thread and in the message loop. Any waiting or blocking action would freeze the screen as no (more) messages were processed.

So, when using a message queue timer you could update the progress bar (and kill or renew the timer as appropriate) and return immediately but not have some lengthy code like performing a slow database query or even connect to another network device.

(2) Using a system timer in a thread

With that your main thread couldn't hang as the timer was in a new thread. You would invoke a new thread (worker thread) which sets a system timer. Then the thread would wait until the timeout. After awakening you would retrieve the progress state (somehow) and post a (private) message to the UI thread.  The UI thread has a handler for that private message and would set the progress-bar according to the progress information given with the message.



 

by: flynnyPosted on 2009-09-24 at 04:01:09ID: 25411897

hi from what i can see does the backgroundworker class not work in its own thread then?

so you'd recommend i went down the system threading method? how can i then access the progress bar using this method?

thanks for all your help in advance!


Matt.

private void tick(object sender, EventArgs e)
        {
            Progress_Bar.PerformStep();
        }
 
            System.Timers.Timer timer = new System.Timers.Timer(); 
            timer.Interval = 1000; 
            timer.Elapsed += new System.Timers.ElapsedEventHandler(tick); 
            timer.Start();
 
            Progress_Bar.Visible = true;
            Progress_Bar.Minimum = 0;
            Progress_Bar.Maximum = 24;
            Progress_Bar.Step = 1;
            Progress_Bar.Value = 0
 
Open in New WindowSelect All

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:

Select allOpen in new window

 

by: TheLearnedOnePosted on 2009-09-25 at 13:52:15ID: 25427143

Is it me, or are you looking for ProgressBar.Style = ProgressBarStyle.Marquee, without any kind of timer, or any other magic...

Windows Forms ProgressBar: Easiest way to start/stop marquee?
http://stackoverflow.com/questions/312936/windows-forms-progressbar-easiest-way-to-start-stop-marquee

Start:
  progressBar1.Style = ProgressBarStyle.Marquee;
  progressBar1.MarqueeAnimationSpeed = 30;

Stop:
  progressBar1.Style = ProgressBarStyle.Block;
  progressBar1.MarqueeAnimationSpeed = 0;




 

by: flynnyPosted on 2009-09-28 at 08:26:59ID: 25440145

hi thats, perfect for my first screen!

however i have a second screen which includes a lengthy sql db creation, population, etc.

i have broken the sql statements down into chunks and store it in a static class.

now to monitor the progress of this i am going to use a public int in the static class containing the sql, so after each sql insert, etc i update the int as to the progress (i.e. add 1 to it after each query).

I then want the timer to poll this integer so it knows how far through the process we are and fill the progress bar accordingly.

so i will need a timer running in a seperate thread. Am i right in thinking that the Background worker is running in a seperate thread?

or should i go back to using the system.threading.thread?

many thanks for everyones help on this,

Matt.

 

by: TheLearnedOnePosted on 2009-09-28 at 08:29:50ID: 25440169

"i have broken the sql statements down into chunks and store it in a static class."
What do you mean by "chunks"?

 

by: flynnyPosted on 2009-09-29 at 00:38:00ID: 25446709

sorry by this i mean i execute each create, insert, seperately.

so for example id execute

CREATE table .....

then update the progress by 1

CREATE second table

update progress

etc....

that way i know how far the program has got through the db creation. so if i poll the global int at any point the returned value should tell me the its progress? do this sound viable?

many thanks for your reply.

Matt.

 

by: TheLearnedOnePosted on 2009-09-29 at 07:02:18ID: 25449096

If you have a BackgroundWorker, and you know how much work needs to be done, then you can use the ReportProgress method, which raises the ProcessChanged event.

BackgroundWorker.ReportProgress Method
http://msdn.microsoft.com/en-us/library/ka89zff4.aspx

C# Copy Code 
// Abort the operation if the user has canceled.
// Note that a call to CancelAsync may have set 
// CancellationPending to true just after the
// last invocation of this method exits, so this 
// code will not have the opportunity to set the 
// DoWorkEventArgs.Cancel flag to true. This means
// that RunWorkerCompletedEventArgs.Cancelled will
// not be set to true in your RunWorkerCompleted
// event handler. This is a race condition.
 
if (worker.CancellationPending)
{   
    e.Cancel = true;
}
else
{   
    if (n < 2)
    {   
        result = 1;
    }
    else
    {   
        result = ComputeFibonacci(n - 1, worker, e) + 
                 ComputeFibonacci(n - 2, worker, e);
    }
 
    // Report progress as a percentage of the total task.
    int percentComplete = 
        (int)((float)n / (float)numberToCompute * 100);
    if (percentComplete > highestPercentageReached)
    {
        highestPercentageReached = percentComplete;
        worker.ReportProgress(percentComplete);
    }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: flynnyPosted on 2009-10-14 at 20:35:37ID: 25577019

thanks sorry for the delay in the reply learnedone.

With this solution i am essentially passing the progress to the background worker.

however, i think in my case it is the other way around.

All of my sql, etc, is in contained in a static class.  

so to explain more, from my windows form i call the sql insertion method which will run setting a global max_progress int (which gives the overall progress to be reched) and a progress int, this is the current progress.

i've been trying to get the background work to poll this every second and this is where the problem is as it (even though i backgroundworker is working on a seperate thread, it doesn't seem to be polling until the sql has completed.)

Now i suppose i could alter the method to pass a reference to the background worker being used and update it tht way? would you recommend doing this, so i could then use report progress that way? the only problem here is that i could just then pass a ref to the progress bar and manually update that then, which kind of defeats the point of running on a seperate thread?

many thanks for all youre help in advance,

Matt.

 

 

by: TheLearnedOnePosted on 2009-10-15 at 05:58:29ID: 25580011

Can you give me some kind of clue how you are using the BackgroundWorker?

 

by: itsmeandnobodyelsePosted on 2009-10-16 at 09:24:53ID: 25590906

>>>> even though i backgroundworker is working on a seperate thread, it doesn't seem to be polling until the sql has completed

Indeed. If you have a lengthy SQL statement to query your background thread would not be able to report progress until all results were received.

There are two ways out:

(1) Show the progress in a timer function of the main thread but show no procentual progress but only the elapsed time until the background thread was done.

(2) Change the select statement so that it receives the results in chunks. E. g. if your data has a contiguous number as an attribute, determine MIN and MAX of that attribute at the beginning and now have - say - 10 queries where the first one would have 'and NUMBER_ATTRIBUTE >= :x and NUMBER_ATTRIBUTE < :y' as an additional condition where x was the minimum number and y was minimum + (maximum-minimum/10);

 

by: flynnyPosted on 2009-10-17 at 07:30:27ID: 25596027

hi thanks for both your comments, as requested heres how i do it

in the button click event is start the background worker as follows;


                backgroundWorker1.RunWorkerAsync();

i then run my static class db creation method.

                SqlClass.CreateDatabase(dbname);

       public static void createDatabase(String db)
        {
            //set max for reading completion status
            max_progress = 28;

            //create a connection
            SqlConnection conn = createConn();
            SqlDataReader reader = null;

            //with create do a select to check exists
            String sql = @" CREATE DATABASE " + db + ";"  +
                         @" SELECT * FROM sys.databases WHERE name = '" + db + "'";

            reader = executeSql(sql, ref conn);

            if(reader == null)
            {
                CustomMessage customMessage = new CustomMessage();
                throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, new Exception(), customMessage.GetString("Create_DB"));
            }

            reader.Close();
            reader = null;

            progress = 1;
           
            sql = @" Use " + db + ";";

            reader = executeSql(sql, ref conn);
            reader.Close();
            reader = null;

            progress = 2;

            sql = @"    CREATE TABLE ....

                        IF EXISTS (...
                        ) SELECT 1 AS res";

            reader = executeSql(sql, ref conn);
           
            if(reader == null)
            {
                CustomMessage customMessage = new CustomMessage();
                throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, new Exception(), customMessage.GetString("Create_centre"));
            }

            reader.Close();
            reader = null;

            progress = 3;

            sql = @"    CREATE TABLE [room]...
                   
                        IF EXISTS (...
                        ) SELECT 1 AS res";

            reader = executeSql(sql, ref conn);

            if(reader == null)
            {
                CustomMessage customMessage = new CustomMessage();
                throw new CustomException.CustomException(SeverityLevel.Fatal, GlobalVars.Debuglog, new Exception(), customMessage.GetString("Create_room"));
            }

            reader.Close();
            reader = null;

           etc... up to 28

and the background worker method is as follows;

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //invoke this and keep looking up the progress and update to the progress bar
            System.Threading.Thread.Sleep(100);
            Progress_Bar.Value = (SqlLogin.Progress * (100/SqlLogin.MaxProgress));
        }

if you need anything else let me know.


many thanks for your time on this.

Matt.

 

by: TheLearnedOnePosted on 2009-10-19 at 05:51:56ID: 25604671

So, you aren't using the ReportProgress event?

 

by: itsmeandnobodyelsePosted on 2009-10-19 at 06:03:11ID: 25604747

You do all the database creation in the button handler?

 

by: flynnyPosted on 2009-10-29 at 01:48:52ID: 25691593

yes to both is this a problem?

do i need to use the reportprogress method?

yes i call the creation method in the static class from the button hanlder method. is there a better way of doing this?

 

by: TheLearnedOnePosted on 2009-10-29 at 06:10:09ID: 25693188

If you are using a BackgroundWorker, and you want progress, then I would suggest handling the ReportProgress event, since that is what the event was meant for.  Trying to get this to work with timers appears to be problematic for you.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...