Autor Beitrag
Xzeer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 62



BeitragVerfasst: So 28.02.10 13:33 
Hallo,

Ich habe eine Frage zur Konsole. Ich möchte eine art Statusbericht in der Konsole ständig aktualisieren. Das mache ich so:

ausblenden C#-Quelltext
1:
2:
3:
4:
//bild aufbauen
Console.Clear();
Console.WriteLine("Lichtsensor: " + board1.AnalogEingang1);
Console.WriteLine("Position: " + positionX + " | " + positionY);


Das funktioniert auch, allerdings ist es nun nicht mehr möglich eine Eingabe zu machen, da diese ja sofort wieder gelöscht wird.

Wie kann ich das Problem lösen?

_________________
Xzeer
patrick
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1481

WIN2k, WIN XP
D6 Personal, D2005 PE
BeitragVerfasst: Do 04.03.10 21:19 
die Lösung lautet SetCursorPos
Damit kann man die aktuelle Position der Cursors innerhalb der Konsole festlegen. Wenn du das aktualisieren der Daten in einen separaten Thread auslagerst ist es möglich parallel dazu eine Abfrage einzubauen.

hier ein kleines Beispielprogramm:

ausblenden volle Höhe C#-Quelltext
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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Test:");
            Console.WriteLine("Blubb:");
            Thread updateThread = new Thread(new ThreadStart(UpdateInfo));
            updateThread.IsBackground = true// Thread wird beendet wenn Programm geschlossen wird
            updateThread.Start();
            Console.ReadKey();
        }

        static void UpdateInfo()
        {
            int i = 0;
            while (true)
            {
                i++;
                Console.SetCursorPosition(00);
                Console.WriteLine("Test:" + i.ToString());
                System.Threading.Thread.Sleep(200);
                Console.SetCursorPosition(01);
                Console.WriteLine("Blubb:" + i.ToString());
                System.Threading.Thread.Sleep(200);
            }    
        }
    }
}

_________________
Patrick
im zweifelsfall immer das richtige tun!!!
Xzeer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 62



BeitragVerfasst: Fr 05.03.10 14:57 
Super :zustimm:

Ich danke dir, dass hat mir sehr geholfen.

_________________
Xzeer