puneet ahooja

puneet ahooja

  • NA
  • 97
  • 20.7k

multithreading ping application in c# windows form

May 12 2017 7:00 AM
Dear Experts,
 
How to Make Multithreading Ping Application in C# windows form.
 
my code is :
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
using System.IO;
using System.Net;
namespace Ping
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Thread th;
private void button1_Click(object sender, EventArgs e)
{
th = new Thread(thread1);
th.Start();
}
public void thread1()
{
try
{
string command = "/c ping " + textBox1.Text;
ProcessStartInfo procStartInfo = new ProcessStartInfo("CMD", command);
Process proc = new Process();
proc.StartInfo = proc.StartInfo;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutPutDataReceived);
proc.Start();
proc.BeginOutputReadLine();
proc.WaitForExit();
}
catch (Exception)
{
}
}
void proc_OutPutDataReceived(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
string newline = e.Data.Trim() + Environment.NewLine;
MethodInvoker append = () => richTextBox1.Text += newline;
richTextBox1.BeginInvoke(append);
}
}
 
 
 

Answers (1)