Click here to Skip to main content
15,938,448 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unable to connect to the remote server when calling web services from code in 4.5 framework. Pin
Gerry Schmitz28-Aug-14 5:28
mveGerry Schmitz28-Aug-14 5:28 
QuestionHow To Use Guid Filter in Select StateMent :( :( :( Pin
mhd.sbt27-Aug-14 19:42
mhd.sbt27-Aug-14 19:42 
AnswerRe: How To Use Guid Filter in Select StateMent :( :( :( Pin
V.28-Aug-14 1:48
professionalV.28-Aug-14 1:48 
GeneralRe: How To Use Guid Filter in Select StateMent :( :( :( Pin
mhd.sbt28-Aug-14 7:54
mhd.sbt28-Aug-14 7:54 
GeneralRe: How To Use Guid Filter in Select StateMent :( :( :( Pin
V.28-Aug-14 19:18
professionalV.28-Aug-14 19:18 
AnswerRe: How To Use Guid Filter in Select StateMent :( :( :( Pin
Richard Deeming28-Aug-14 1:49
mveRichard Deeming28-Aug-14 1:49 
GeneralRe: How To Use Guid Filter in Select StateMent :( :( :( Pin
mhd.sbt30-Aug-14 4:37
mhd.sbt30-Aug-14 4:37 
QuestionProgress Bar makes copying painfully slow, a little help please? Pin
kiasta27-Aug-14 17:26
kiasta27-Aug-14 17:26 
I've implemented a progress bar to my application but it makes the file copy process painfully slow whereas without the progress bar the copy is very fast. I know without the progress bar it only takes a few seconds to copy a 10 megabyte file but with the progress bar it takes more than a minute. What am I doing wrong?



C#
namespace Compression_Util
{
    class DropBox
    {
        private object sender;
        private EventArgs e;
        private DragEventArgs de;
        private Design zip;
        private string hover;
        private string[] files;
        private string filetype;

        public DropBox(object sender, DragEventArgs de, Design zip, string hover)
        {
            this.sender = sender;
            this.de = de;
            this.zip = zip;
            this.hover = hover;
            this.Hover();
        }

        public DropBox(object sender, EventArgs e, Design zip, string hover)
        {
            this.sender = sender;
            this.e = e;
            this.zip = zip;
            this.hover = hover;
            this.Hover();
        }

        private void InitializeProgressBar(int fileSize)
        {
            zip.DropProgress.Visible = true;
            zip.DropProgress.Minimum = sizeof(Byte);
            zip.DropProgress.Step = sizeof(Byte);
            zip.DropProgress.Maximum = fileSize;
        }

        private void DeInitializeProgressBar()
        {
            zip.DropProgress.Invalidate();
            zip.DropProgress.Visible = false;
        }

        private void IncrementProgressBar()
        {
            zip.DropProgress.PerformStep();
        }

        private void CreateFile(string read, string write)
        {
            try
            {
                FileStream fileStreamReader = new FileStream(read, FileMode.Open, FileAccess.Read);
                FileStream fileStreamWriter = new FileStream(write, FileMode.Create, FileAccess.ReadWrite);
                BinaryReader binaryReader = new BinaryReader(fileStreamReader);
                BinaryWriter binaryWriter = new BinaryWriter(fileStreamWriter);
                int position = 0;
                int length = (int)binaryReader.BaseStream.Length;
                InitializeProgressBar(length);
                while (position < length)
                {
                    Byte line = binaryReader.ReadByte();
                    binaryWriter.Write(line);
                    position += sizeof(Byte);
                    IncrementProgressBar();
                }
                DeInitializeProgressBar();
                binaryWriter.Close();
                binaryReader.Close();
                fileStreamWriter.Close();
                fileStreamReader.Close();
            }
            catch (FileNotFoundException FileEx)
            {
                MessageBox.Show(FileEx.Message);
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }

        private string CreateFileName(string file)
        {
            int i = 0;
            string deleteText = "";
            string newFileName = "";
            while ((i = file.IndexOf('.', i)) != -1)
            {
                deleteText = file.Substring(i);
                i++;
            }
            this.filetype = deleteText;
            //MessageBox.Show(deleteText);
            newFileName = file.Replace(deleteText, ".xxx"); //For Custom Filetype
            return newFileName;
        }
        private void Hover()
        {
            switch (this.hover)
            {
                case "Enter":
                    {
                        zip.DragLabel.Visible = false;
                        zip.DropLabel.Visible = true;
                        zip.BackColor = System.Drawing.Color.DarkGray;
                        zip.DropBox.BackColor = System.Drawing.Color.Thistle;
                        zip.DropBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                        if (de.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
                        {
                            de.Effect = DragDropEffects.All;
                        }
                        break;
                    }
                case "Leave":
                    {
                        zip.DragLabel.Visible = true;
                        zip.DropLabel.Visible = false;
                        zip.BackColor = System.Drawing.Color.WhiteSmoke;
                        zip.DropBox.BackColor = System.Drawing.Color.WhiteSmoke;
                        zip.DropBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        break;
                    }
                case "Drop":
                    {
                        zip.DragLabel.Visible = true;
                        zip.DropLabel.Visible = false;
                        zip.BackColor = System.Drawing.Color.WhiteSmoke;
                        zip.DropBox.BackColor = System.Drawing.Color.WhiteSmoke;
                        zip.DropBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        this.Drop();
                        break;
                    }
            }
        }
        private void Drop()
        {
            this.files = (string[])this.de.Data.GetData(DataFormats.FileDrop);
            foreach (string file in files)
            {
                //MessageBox.Show(file);
                string newFileName = this.CreateFileName(file);
                //MessageBox.Show(newFileName);
                if (!File.Exists(newFileName))
                {
                    this.CreateFile(file, newFileName);
                }
                else
                {
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    DialogResult result;
                    string message = "File already exists, Overwrite?";
                    string caption = "";
                    result = MessageBox.Show(zip, message, caption, buttons);
                    switch (result)
                    {
                        case DialogResult.Yes:
                            {
                                this.CreateFile(file, newFileName);
                                break;
                            }
                        case DialogResult.No:
                            {
                                MessageBox.Show("Operation has been cancelled!");
                                break;
                            }
                        default: break;
                    }
                }
            }
        }
    }
}

AnswerRe: Progress Bar makes copying painfully slow, a little help please? Pin
Ravi Bhavnani27-Aug-14 17:44
professionalRavi Bhavnani27-Aug-14 17:44 
GeneralRe: Progress Bar makes copying painfully slow, a little help please? Pin
kiasta28-Aug-14 4:20
kiasta28-Aug-14 4:20 
AnswerRe: Progress Bar makes copying painfully slow, a little help please? Pin
Roger50027-Aug-14 18:04
Roger50027-Aug-14 18:04 
GeneralRe: Progress Bar makes copying painfully slow, a little help please? Pin
kiasta28-Aug-14 5:03
kiasta28-Aug-14 5:03 
GeneralRe: Progress Bar makes copying painfully slow, a little help please? Pin
Roger50028-Aug-14 11:51
Roger50028-Aug-14 11:51 
GeneralRe: Progress Bar makes copying painfully slow, a little help please? Pin
kiasta29-Aug-14 8:46
kiasta29-Aug-14 8:46 
AnswerRe: Progress Bar makes copying painfully slow, a little help please? Pin
OriginalGriff27-Aug-14 22:36
mveOriginalGriff27-Aug-14 22:36 
GeneralRe: Progress Bar makes copying painfully slow, a little help please? Pin
kiasta28-Aug-14 5:08
kiasta28-Aug-14 5:08 
QuestionFacing Problems in your Code Pin
Member 1019429727-Aug-14 16:07
Member 1019429727-Aug-14 16:07 
AnswerRe: Facing Problems in your Code Pin
Dave Kreskowiak27-Aug-14 17:27
mveDave Kreskowiak27-Aug-14 17:27 
QuestionRe: Facing Problems in your Code Pin
ZurdoDev28-Aug-14 4:23
professionalZurdoDev28-Aug-14 4:23 
AnswerRe: Facing Problems in your Code Pin
Gerry Schmitz28-Aug-14 5:36
mveGerry Schmitz28-Aug-14 5:36 
QuestionC# 2013 Pin
shawnjots27-Aug-14 13:12
shawnjots27-Aug-14 13:12 
AnswerRe: C# 2013 Pin
Richard MacCutchan27-Aug-14 22:17
mveRichard MacCutchan27-Aug-14 22:17 
AnswerRe: C# 2013 Pin
Sibeesh KV29-Sep-14 19:26
professionalSibeesh KV29-Sep-14 19:26 
Questionget string from via Regex Pin
jojoba2027-Aug-14 7:02
jojoba2027-Aug-14 7:02 
AnswerRe: get string from via Regex Pin
Rob Philpott27-Aug-14 9:13
Rob Philpott27-Aug-14 9:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.