Click here to Skip to main content
15,905,612 members
Home / Discussions / C#
   

C#

 
GeneralRe: add seven segment to visual studio 2012 Pin
Sascha Lefèvre30-Apr-15 4:26
professionalSascha Lefèvre30-Apr-15 4:26 
QuestionPBX Call Log Pin
Member 1011228329-Apr-15 18:19
Member 1011228329-Apr-15 18:19 
AnswerRe: PBX Call Log Pin
OriginalGriff29-Apr-15 21:31
mveOriginalGriff29-Apr-15 21:31 
GeneralRe: PBX Call Log Pin
Member 1011228329-Apr-15 21:36
Member 1011228329-Apr-15 21:36 
GeneralRe: PBX Call Log Pin
OriginalGriff29-Apr-15 22:04
mveOriginalGriff29-Apr-15 22:04 
GeneralRe: PBX Call Log Pin
Member 1011228330-Apr-15 2:51
Member 1011228330-Apr-15 2:51 
GeneralRe: PBX Call Log Pin
Simon_Whale30-Apr-15 2:01
Simon_Whale30-Apr-15 2:01 
GeneralRe: PBX Call Log Pin
Member 1011228330-Apr-15 2:30
Member 1011228330-Apr-15 2:30 
GeneralRe: PBX Call Log Pin
Simon_Whale30-Apr-15 2:34
Simon_Whale30-Apr-15 2:34 
GeneralRe: PBX Call Log Pin
Member 1011228330-Apr-15 2:41
Member 1011228330-Apr-15 2:41 
GeneralRe: PBX Call Log Pin
F-ES Sitecore30-Apr-15 3:15
professionalF-ES Sitecore30-Apr-15 3:15 
AnswerRe: PBX Call Log Pin
BillWoodruff30-Apr-15 1:56
professionalBillWoodruff30-Apr-15 1:56 
QuestionWinForms Update A Dialog Pin
Kevin Marois29-Apr-15 9:24
professionalKevin Marois29-Apr-15 9:24 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 9:34
professionalSascha Lefèvre29-Apr-15 9:34 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 9:37
professionalKevin Marois29-Apr-15 9:37 
AnswerRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 10:32
professionalSascha Lefèvre29-Apr-15 10:32 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 10:37
professionalKevin Marois29-Apr-15 10:37 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 10:57
professionalSascha Lefèvre29-Apr-15 10:57 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 10:58
professionalKevin Marois29-Apr-15 10:58 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 11:17
professionalSascha Lefèvre29-Apr-15 11:17 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 11:23
professionalKevin Marois29-Apr-15 11:23 
GeneralRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 11:50
professionalSascha Lefèvre29-Apr-15 11:50 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 11:54
professionalKevin Marois29-Apr-15 11:54 
GeneralRe: WinForms Update A Dialog Pin
Kevin Marois29-Apr-15 12:23
professionalKevin Marois29-Apr-15 12:23 
AnswerRe: WinForms Update A Dialog Pin
Sascha Lefèvre29-Apr-15 13:00
professionalSascha Lefèvre29-Apr-15 13:00 
Don't put any UI stuff into the BW. It should look something like the following. Not tested, obviously, and it's a bit hacky. It would actually make sense to start the BW from the DownloadDialog in order to ensure that the DownloadDialog "exists" when ProgressChanged and RunWorkerCompleted fire.
C#
class Form1 : Form
{
    BackgroundWorker worker;
    DownloadDialog downloadDialog;

    public Form1()
    {
        InitializeComponent();

        worker = new BackgroundWorker();
        worker.WorkerReportsProgress = true;
        worker.ProgressChanged += worker_ProgressChanged;
        worker.DoWork += worker_DoWork;
        worker.RunWorkerCompleted += worker_RunWorkerCompleted;
    }

    void DownloadStartButton_Click(object sender, EventArgs e)
    {
        DownloadDeviceFiles();
    }

    void DownloadDeviceFiles()
    {
        worker.RunWorkerAsync();

        DownloadDialog downloadDialog = new DownloadDialog();
        downloadDialog.Text = "Retrieving Mission Data";
        downloadDialog.Progress1Caption = "Config File";
        downloadDialog.Progress2Caption = "Database";
        downloadDialog.StartPosition = FormStartPosition.CenterScreen;

        downloadDialog.ShowDialog(this);
    }

    void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        e.Result = DownloadConfigFile() && DownloadDatabase();
    }

    void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
        // I didn't account for the fact here that you have two separate progressbars

        if (downloadDialog != null)
            downloadDialog.Progress1PercentDone = e.ProgressPercentage;
    }

    void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        downloadDialog.Close();
        downloadDialog.Dispose();

        if (e.Result == true)
            // continue app
        else
            // close app
    }

    bool DownloadConfigFile() // same for DownloadDatabase()
    {
        // ... init ...

        while (true)
        {
            // downloadstuff

            worker.ReportProgress(percentDone);
        }

        return downloadSuccess;
    }
}

If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

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.