@ErfinderDesRades (hab dich mal markiert weil du das Thema ja geschrieben hast)
Ich hab mich in folgendes Thema eingelesen => Cmd-Remote
Da das in VB geschrieben hab ich alles in C# umgeschrieben bzw. versucht.
Folgendes Probleme. a) BeginInvoke
b) Output wird nicht angezeigt
a) Da ich mir mit dem BeginInvoke nicht sicher war hab ich das Folgendermaßen "gelöst" =>
Es zeigt mir keinen Fehler an wollte trotzdem wissen ob das richtig is ?
b) Auch wenn mein Code keine Fehler ausspuckt bekomm ich keinen Output angezeigt in meiner Richtextbox.
Folgenden Code hab' ich:
Ich hab mir den mehrfach durchgelesen werd aber nicht schlau. Tipps?
Grüße,
Fachkraft
Ich hab mich in folgendes Thema eingelesen => Cmd-Remote
Da das in VB geschrieben hab ich alles in C# umgeschrieben bzw. versucht.
Folgendes Probleme. a) BeginInvoke
b) Output wird nicht angezeigt
a) Da ich mir mit dem BeginInvoke nicht sicher war hab ich das Folgendermaßen "gelöst" =>
Es zeigt mir keinen Fehler an wollte trotzdem wissen ob das richtig is ?
b) Auch wenn mein Code keine Fehler ausspuckt bekomm ich keinen Output angezeigt in meiner Richtextbox.
Folgenden Code hab' ich:
C#-Quellcode
- 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 Microsoft.WindowsAPICodePack;
- using Microsoft.WindowsAPICodePack.Shell;
- using System.IO;
- using System.Reflection;
- using Microsoft.WindowsAPICodePack.ApplicationServices;
- using Microsoft.WindowsAPICodePack.Taskbar;
- using System.Diagnostics;
- namespace DiesdasAnnanass
- {
- public partial class Form1 : Form
- {
- ThumbnailToolBarButton thumbnailButton = new ThumbnailToolBarButton(new Icon("box.ico", 16, 16), "Show MessageBox");
- Process _process = new Process { EnableRaisingEvents = true };
- public Form1()
- {
- InitializeComponent();
- thumbnailButton.Click += new EventHandler<ThumbnailButtonClickedEventArgs>(handleClick);
- TaskbarManager.Instance.ThumbnailToolBars.AddButtons(this.Handle, thumbnailButton);
- Point clipPoint = new Point(0, 0);
- Size clipSize = new System.Drawing.Size(100, 100);
- Rectangle clipRectangle = new Rectangle(clipPoint, clipSize);
- TaskbarManager.Instance.TabbedThumbnail.SetThumbnailClip(this.Handle, clipRectangle);
- }
- void Execute()
- {
- if (_process == null)
- {
- MessageBox.Show("Process nicht gestartet.");
- }
- _process.StandardInput.WriteLine(txtInput.Text);
- txtInput.Text = "";
- }
- private void LaunchConsoleProcess()
- {
- var _with1 = _process.StartInfo;
- _with1.CreateNoWindow = true;
- _with1.UseShellExecute = false;
- _with1.FileName = "cmd";
- _with1.RedirectStandardInput = true;
- _with1.RedirectStandardOutput = true;
- if (!_process.Start()) { MessageBox.Show("Fail"); return; }
- _process.BeginOutputReadLine();
- }
- delegate void OutPutDataRecievedDelegate(object sender, DataReceivedEventArgs e);
- private void _Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
- {
- var del = new OutPutDataRecievedDelegate(_Process_OutputDataReceived);
- BeginInvoke(new Action(() => this.OutputData(e.Data)));
- }
- delegate void SetTextBoxTextDelegate(RichTextBox txtBox, string txt);
- void SetTextBoxText(RichTextBox txtBox, string txt)
- {
- if (txtBox.InvokeRequired)
- {
- var del = new SetTextBoxTextDelegate(SetTextBoxText);
- txtBox.Parent.Invoke(del, txtBox, txt);
- }
- else txtBox.Text += txt;
- }
- public delegate void OutPutDataDelegate();
- private void OutputData(string txt)
- {
- txtLog.AppendText(txt);
- txtLog.Select(txtLog.TextLength, 0);
- txtLog.ScrollToCaret();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- void handleClick(object sender, ThumbnailButtonClickedEventArgs e)
- {
- MessageBox.Show("ThumbnailButton Example");
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Execute();
- string output = _process.StandardOutput.ReadToEnd();
- txtLog.Text = output;
- }
- private void startToolStripMenuItem_Click(object sender, EventArgs e)
- {
- LaunchConsoleProcess();
- txtLog.Text = "";
- }
- private void txtInput_KeyDown(object sender, KeyEventArgs e)
- {
- if(e.KeyCode == Keys.Enter)
- {
- e.Handled = true;
- e.SuppressKeyPress = true;
- Execute();
- }
- }
- private void btExecute_Click(object sender, EventArgs e)
- {
- Execute();
- }
- }
- }
Ich hab mir den mehrfach durchgelesen werd aber nicht schlau. Tipps?
Grüße,
Fachkraft