Diskuze: C# konzolova pliakcia - vystup
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.

Člen

Zobrazeno 14 zpráv z 14.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
Vyzkoušej něco takového.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace smazatX
{
class Program
{
static void Main(string[] args)
{
new Program().StartAndLoop();
}
private void StartAndLoop()
{
Label label = new Label { Text = "" };
Form form = new Form { Controls = { label } };
new Thread(() => Application.Run(form)).Start();
while (true)
{
string line = Console.ReadLine();
Action updateText = () => label.Text = line;
label.Invoke(updateText);
}
}
}
}
alternativne muzes pouzit event OutputDataReceived.
http://msdn.microsoft.com/….110%29.aspx
Caute, dakujem za odpoved. Ale ako to upravim ked mam teraz takyto tvar:
Process ScanMemory = new Process();
process.StartInfo.FileName = "C:\\program.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
textBox1.Text = process.StandardOutput.ReadToEnd();
Vite mi to tu prosim nejako upravit. Som uplny zaciatocnik
private Process process;
private StreamReader myStreamReader;
private void Form1_Load(object sender, EventArgs e)
{
process = new Process();
process.StartInfo.FileName = "C:\\__SMAZAT\\program.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
myStreamReader = process.StandardOutput;
if (myStreamReader == null) return;
label1.Text += myStreamReader.ReadLine();
}
catch
{
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace TestA1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Process process;
private StreamReader myStreamReader;
private void button1_Click(object sender, EventArgs e)
{
process = new Process();
process.StartInfo.FileName = "C:\\__SMAZAT\\program.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
myStreamReader = process.StandardOutput;
if (myStreamReader == null) return;
label1.Text += myStreamReader.ReadLine();
}
catch
{
}
}
Přidej Timer a na jeho Tick (timer1_Tick) se ptám co říká ta konzolovka
Zde to je celé. Ten timer tam mít nemusíš. Záleží co to bude dělat a jak ti to bude vyhovovat:)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SmazatXX
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Process process;
private StreamReader myStreamReader;
private System.Windows.Forms.Timer timer1;
private void Form1_Load(object sender, EventArgs e)
{
process = new Process();
process.StartInfo.FileName = "C:\\__SMAZAT\\program.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
myStreamReader = process.StandardOutput;
if (myStreamReader == null) return;
label1.Text += myStreamReader.ReadLine();
}
catch
{
}
}
}
}
Zobrazeno 14 zpráv z 14.