tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
1454
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    realbora realbora ist offline Mitglied
    Registriert seit
    Aug 2007
    Beiträge
    23
    Hallo,

    ich versuche z.Zt. eine CF-Anwendung zu programmieren, die beim Start verschiedene Einstellungen über einen Webservice aus einer DB lädt. Vor diesem Prozess(Thread) soll ein anderer Thread gestartet werden, der den Verlauf des Ladevorgangs mittels einer ProgressBar anzeigt. Mittels Invoke und den dazugehörigen Events versuche ich nun die Threads zu steuern, was aber bis jetzt leider nicht zum Erfolg geführt hat.

    Vielleicht kann mir ja hier jemand helfen?

    Danke.

    Code :
    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
    
            public Form_KeKa(Mitarbeiter arg1, Tisch arg2 ,WebserviceKeKa arg3)
            {
                this.m_Mitarbeiter = arg1;
                this.m_Tisch = arg2;
                this.m_WebserviceKeKa = arg3;
     
                //Event-Handler
                this.Resize += new EventHandler(this.Form_Resize);
     
                //Methoden
                InitializeComponent();
     
                Thread t1 = new Thread(new ThreadStart(OnShowProgressBar));
                t1.Start();
                Thread t2 = new Thread(new ThreadStart(OnFillProgressBar));
                t2.Start();
     
                Initialize_Panel_Main();
     
                //Attribute
                //SHFullScreenHelper.ShowSIPButton(this, false); 
     
                //Controlls
                this.Controls.Add(this.m_Panel_Main);
                Keyboard k = new Keyboard(this);
                this.Controls.Add(k);
            }
     
            delegate void ShowProgressBar();
            private void OnShowProgressBar()
            {
                if (this.s_Form_Progress.InvokeRequired)
                {
                    this.s_Form_Progress.Invoke(new ShowProgressBar(OnShowProgressBar));
                    return;
                }
                this.s_Form_Progress.ShowDialog();
            }
     
            delegate void FillProgressBar();
            private void OnFillProgressBar()
            {
                if (this.s_Form_Progress.InvokeRequired)
                {
                    this.s_Form_Progress.Invoke(new FillProgressBar(OnFillProgressBar));
                    return;
                }
                for (int i = 0; i < 100; i++)
                {
                    Thread.Sleep(20);
                    OnUpdateProgressBar(i);
                }
                OnFinished(null, null);
            }
     
            delegate void UpdateProgressBar(int i);
            private void OnUpdateProgressBar(int i)
            {
                if (s_Form_Progress.InvokeRequired)
                {
                    s_Form_Progress.Invoke(new UpdateProgressBar(OnUpdateProgressBar), new object[] { i });
                    return;
                }
                if (i < s_Form_Progress.ProgressBar.Maximum)
                {
                    s_Form_Progress.ProgressBar.Value = i;
                }
            }
     
            delegate void FinishedProgressBar(object sender, EventArgs e);
            private void OnFinished(object sender, EventArgs e)
            {
                if (s_Form_Progress.ProgressBar.InvokeRequired)
                {
                    s_Form_Progress.Invoke(new FinishedProgressBar(OnFinished));
                    return;
                }
                s_Form_Progress.Close();
            }
    ...
     

  2. #2
    realbora realbora ist offline Mitglied
    Registriert seit
    Aug 2007
    Beiträge
    23
    Habe eine Lösung gefunden.

    Code :
    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
    109
    110
    111
    112
    113
    114
    115
    116
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
     
    namespace TestThread
    {
        public partial class Form1 : Form
        {
            private Form_Progress m_Form_Progress = new Form_Progress();
            Thread t1;
            Thread t2;
            Thread t3;
            Thread t4;
     
            public Form1()
            {
                Application.DoEvents();
                t1 = new Thread(new ThreadStart(OnShowProgressBar));
                t1.Start();
     
                t2 = new Thread(new ThreadStart(OnFillProgressBar));
                t2.Start();
     
                t3 = new Thread(new ThreadStart(Worker));
                t3.Start();
     
                t4 = new Thread(new ThreadStart(OnInit));
                t4.Start();
            }
     
            private void Worker()
            {
                for (int i = 0; i < 50000; i++)
                {
                    int x = new Random().Next() + i;
                    //double y = Math.Pow(x,Math.Cos(x)) * Math.Pow(x, Math.Sin(x));
                }
                System.Diagnostics.Debug.WriteLine("Ende");
                t3.Abort();
            }
     
            delegate void Init();
            private void OnInit()
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new Init(OnInit)); 
                    return;
                }
                InitializeComponent();
                t4.Abort();
            }
     
     
            delegate void ShowProgressBar();
            private void OnShowProgressBar()
            {
                if (this.m_Form_Progress.InvokeRequired)
                {
                    this.m_Form_Progress.Invoke(new ShowProgressBar(OnShowProgressBar));
                    return;
                }
     
                this.m_Form_Progress.ShowDialog();
                t1.Abort();
            }
     
            delegate void FillProgressBar();
            private void OnFillProgressBar()
            {
                if (this.m_Form_Progress.InvokeRequired)
                {
                    this.m_Form_Progress.Invoke(new FillProgressBar(OnFillProgressBar));
                    return;
                }
                for (int i = 0; i < 100; i++)
                {
                    Thread.Sleep(20);
                    OnUpdateProgressBar(i);
                }
                OnFinished(null, null);
                t2.Abort();
            }
     
            delegate void UpdateProgressBar(int i);
            private void OnUpdateProgressBar(int i)
            {
                if (this.m_Form_Progress.InvokeRequired)
                {
                    this.m_Form_Progress.Invoke(new UpdateProgressBar(OnUpdateProgressBar), new object[] { i });
                    return;
                }
                if (i < this.m_Form_Progress.ProgressBar.Maximum)
                {
                    this.m_Form_Progress.ProgressBar.Value = i;
                }
            }
     
            delegate void FinishedProgressBar(object sender, EventArgs e);
            private void OnFinished(object sender, EventArgs e)
            {
                if (this.m_Form_Progress.ProgressBar.InvokeRequired)
                {
                    this.m_Form_Progress.Invoke(new FinishedProgressBar(OnFinished));
                    return;
                }
                this.m_Form_Progress.Close();
            }
     
        }
    }
     

Ähnliche Themen

  1. .NET Compact Framework 2.0 Problem
    Von reuchlein im Forum .NET Café
    Antworten: 2
    Letzter Beitrag: 02.10.09, 17:23
  2. .NET Compact Framework 3.5
    Von Mexxchen im Forum .NET Café
    Antworten: 0
    Letzter Beitrag: 16.11.08, 22:45
  3. Compact Framework Bluetooth
    Von Trebjun im Forum .NET Windows Forms
    Antworten: 0
    Letzter Beitrag: 15.06.07, 17:13
  4. Compact Framework und Kryptographie
    Von MD1978 im Forum .NET Archiv
    Antworten: 1
    Letzter Beitrag: 15.12.04, 10:05
  5. Compact Framework und Serialisieren
    Von manschi im Forum .NET Archiv
    Antworten: 3
    Letzter Beitrag: 14.12.04, 09:16