Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:21:17+00:00 2026-06-12T15:21:17+00:00

I have a small popup window like so: using System; using System.Collections.Generic; using System.ComponentModel;

  • 0

I have a small popup window like so:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SQLProcWriter
{
    public partial class Progress : Form
    {
        public Progress()
        {
            InitializeComponent();
            progressBar1.Minimum = 0;
            progressBar1.Maximum = 100;
        }
    }
}

namespace SQLProcWriter
{
    partial class Progress
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Progress));
            this.progressBar1 = new System.Windows.Forms.ProgressBar();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // progressBar1
            // 
            resources.ApplyResources(this.progressBar1, "progressBar1");
            this.progressBar1.Name = "progressBar1";
            this.progressBar1.UseWaitCursor = true;
            // 
            // label1
            // 
            resources.ApplyResources(this.label1, "label1");
            this.label1.Name = "label1";
            this.label1.UseWaitCursor = true;
            // 
            // Progress
            // 
            resources.ApplyResources(this, "$this");
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.label1);
            this.Controls.Add(this.progressBar1);
            this.Name = "Progress";
            this.UseWaitCursor = true;
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        public System.Windows.Forms.ProgressBar progressBar1;
        public System.Windows.Forms.Label label1;
    }
}

It’s supposed to show the progress of a file I’m loading and processing. The problem is that it doesn’t render the progress bar or the label until after the file is finished processing; the form is created on the main windows’ load method, and shown once an openfiledialog has completed with an ‘OK’ result. Any help?

EDIT: The code for the setting of the value is quite extensive, so I originally opted to remove it, but here it is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace SQLProcWriter
{
    public partial class Form1 : Form
    {
        private string Script { get; set; }
        private List<string> File { get; set; }
        private List<string> CreateStatements { get; set; }
        private List<Table> Tables { get; set; }
        private List<string> FieldBuffer { get; set; }
        private Progress progressWindow;
        private int progressValue;

        private const string CREATE_SEPARATOR = "create table ";
        private string[] FIELD_SEPARATOR = new string[] { @"\t", @" "};

        public Form1()
        {
            InitializeComponent();
            File = new List<string>();
            FieldBuffer = new List<string>();
            Tables = new List<Table>();
            CreateStatements = new List<string>();
            progressValue = 0;
            progressWindow = new Progress();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About about = new About();
            about.Show();
        }

        private void Convert()
        {
            bool adding = false, nullableBuffer = false;
            string buffer = "", buffer2 = "";
            Table currentTable = new Table();
            currentTable.ForeignKeys = new List<ForeignKey>();
            currentTable.Columns = new List<Column>();
            int startIndex = 0, endIndex = 0;
            int linesDone = 0;
            int totalLines = File.Count();
            progressWindow.label1.Text = "Reading \'Create\' Statements";

            foreach (string s in File)
            {
                //Extract column names
                if (adding)
                {
                    if (s.Contains(@")") && s.Length == 1)
                    {
                        adding = false;
                        Tables.Add(currentTable);
                        currentTable = new Table();
                        currentTable.Columns = new List<Column>();
                        currentTable.ForeignKeys = new List<ForeignKey>();
                        currentTable.TableName = "";
                        currentTable.PrimaryKey = new PrimaryKey();
                    }
                    else
                    {
                        if (s != @"(")
                        {
                            if (s != "\t")
                            {
                                if (s.Contains("constraint"))
                                {
                                    //Constraint rules here
                                    if (s.Contains("primary key clustered"))
                                    {
                                        startIndex = s.IndexOf("(");
                                        startIndex++;
                                        endIndex = s.IndexOf(")");

                                        buffer = s.Substring(startIndex, (endIndex - startIndex));


                                        currentTable.PrimaryKey = new PrimaryKey(buffer, "int");
                                    }
                                    else if (s.Contains("foreign key"))
                                    {
                                        startIndex = s.IndexOf("(");
                                        startIndex++;
                                        endIndex = s.IndexOf(")");
                                        buffer = s.Substring(startIndex, (endIndex - startIndex));

                                        startIndex = s.IndexOf("references ");
                                        startIndex += 11;
                                        endIndex = s.Length;

                                        buffer2 = s.Substring(startIndex, (endIndex - startIndex));
                                        endIndex = buffer2.IndexOf(String.Format("({0}", buffer));
                                        buffer2 = buffer2.Substring(0, endIndex);


                                        currentTable.ForeignKeys.Add(new ForeignKey(buffer, buffer2));
                                    }
                                }
                                else
                                {
                                    //Regular table field
                                    buffer = s.Substring(s.IndexOf("\t") + 1, s.IndexOf(" "));

                                    startIndex = s.IndexOf(" ");
                                    startIndex++;
                                    endIndex = s.IndexOf(",");

                                    buffer2 = s.Substring(startIndex, (endIndex - startIndex));

                                    if (buffer2.Contains("not null"))
                                    {
                                        nullableBuffer = false;
                                        buffer2 = buffer2.Remove(buffer2.IndexOf(" "));
                                    }
                                    else
                                        nullableBuffer = true;

                                    currentTable.Columns.Add(new Column(buffer, buffer2, nullableBuffer));
                                }
                            }
                        }
                    }
                }

                //Extract Table Names
                if (s.Contains(CREATE_SEPARATOR))
                {
                    adding = true;
                    buffer = s;
                    currentTable.TableName = buffer.Remove(0, 13);
                }

                linesDone++;
                progressValue = (((linesDone / totalLines) * 100) / 4) + 25;
                progressWindow.progressBar1.Value = progressValue;
            }

            ProcessForeignKeys();
            ProcessPrimaryKeys();
            Tables = Utils.TrimEverything(Tables);
        }

        private void ProcessForeignKeys()
        {
            int keysDone = 0;
            int totalKeys = 0;
            progressWindow.label1.Text = "Processing Foreign Keys";

            foreach (Table t in Tables)
                foreach (ForeignKey fk in t.ForeignKeys)
                    totalKeys++;

            foreach (Table t in Tables)
                foreach (ForeignKey fk in t.ForeignKeys)
                {
                    for (int i = 0; i < t.Columns.Count; i++)
                        if (t.Columns[i].Name.Contains(fk.Name))
                        {
                            fk.DataType = t.Columns[i].DataType;
                            t.Columns.RemoveAt(i);
                        }

                    keysDone++;
                    progressValue = (((keysDone / totalKeys) * 100) / 4) + 50;
                }
        }

        private void ProcessPrimaryKeys()
        {
            int primaryKeys = 0;
            int totalKeys = Tables.Count();
            progressWindow.label1.Text = "Processing Primary Keys";

            foreach (Table t in Tables)
            {
                for (int i = 0; i < t.Columns.Count; i++)
                {
                    if (t.Columns[i].DataType.Contains("identity"))
                    {
                        t.Columns.RemoveAt(i);
                        primaryKeys++;
                        progressValue = (((primaryKeys / totalKeys) * 100) / 4) + 75;
                        progressWindow.progressBar1.Value = progressValue;
                    }
                }
            }

            progressWindow.label1.Text = "Done!";
            progressWindow.Hide();
            progressWindow.progressBar1.Value = 0;
            progressWindow.label1.Text = "";
            progressValue = 0;
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OutputTextBox.Text = "";
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();
            ofd.Filter = "SQL Script File (.sql)|*.sql";
            ofd.Multiselect = false;
            ofd.Title = "Select an SQL Script File";

            Stream fileStream = null;

            int currentLine = 0;
            int totalLines = 0;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                progressWindow.Show();

                if ((fileStream = ofd.OpenFile()) != null)
                {
                    TextReader tr = new StreamReader(fileStream);
                    string line;
                    totalLines = System.IO.File.ReadLines(ofd.FileName).Count();

                    while ((line = tr.ReadLine()) != null)
                    {
                        File.Add(line);
                        OutputTextBox.Text += line + "\r\n";

                        currentLine++;
                        progressValue = (int)(((currentLine / totalLines) * 100) / 4);
                        progressWindow.progressBar1.Value = progressValue;
                    }

                    Convert();
                }
            }
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            Script = string.Empty;
            OutputTextBox.Text = string.Empty;
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ConvertButton_Click(object sender, EventArgs e)
        {
            List<string> Output = new List<string>();
            progressWindow.Show();
            progressWindow.label1.Text = "Creating SQL";
            int total = Tables.Count();
            int done = 0;

            Output.Add(String.Format("--Auto-generated code (c) {0} Logic & Design", System.DateTime.Now.Year));

            foreach (Table t in Tables)
            {
                //Add a comment
                Output.Add(String.Format("--Procs for {0}", t.TableName));

                #region List
                Output.Add(String.Format("create proc {0}_List", t.TableName));
                Output.Add("as");
                Output.Add(String.Format("\tselect * from {0}", t.TableName));
                #endregion

                #region Get
                Output.Add(String.Format("create proc {0}_Get", t.TableName));
                Output.Add(String.Format("@{0} {1}", t.PrimaryKey.Name, t.PrimaryKey.DataType));
                Output.Add("as");
                Output.Add(String.Format("\tif"));
                #endregion

                #region Create
                #endregion

                #region Update
                #endregion

                #region Delete
                #endregion

                done++;
                progressValue = (done / total) * 100;
                progressWindow.progressBar1.Value = progressValue;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:21:19+00:00Added an answer on June 12, 2026 at 3:21 pm

    I suggest you let the file be opened asynchronously. Maybe call BeginOpenFile or some similar, let the completion function update the progress bar to 100 or 99 percent then close it via Form.Invoke or similar. Meanwhile have a timer inside the progress form that advances 10% progress once a given number of milliseconds, say 100ms.
    but don’t let it set the progress after reaching 90 percent.
    You can’t tell for sure how much time will it take to open the file, you can only estimate. That’s why progress bars in any application tend not to be accurate.

    Note: not sure if timer resolution can be smaller than a second (1000ms)…

    If you need to learn about asynchronous operations in C# a good resource is “CLR via C#”. If you can’t have that book try googling for “performing asynchrounos IO operation .NET” and look into a code example for File.BeginRead for example.

    And don’t forget the Form.Invoke thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small popup window with dynamic contents. Nothing too complex. It has
In my application I have a window which I popup with small messages on
I have small database of business and their addresses. Using the Google Geocode API
I am making a small application and would like a small popup to come
I am doing a website using asp.net C# and I would like to popup
I have anchor tag inside a gridview which im using javascript onclick to popup
So i am building a 'like' button but i have a small problem after
i have small problem i.e. their is one celltable with lot of data it
This HyperLink syntax is not working to pass parameters to a small PopUp window:
I'm trying to create a window that will become a small popup window, containing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.