flokli
Erfahrenes Mitglied
Hallo,
probiere jetzt mal C# aus, habe nur ein Problem mit der (Sichtbarkeit?) der Unterklassen/Methoden in einer Form.
Form1.cs
enthält u.a. eine Statusleiste (toolStripProgressBar1, toolStripStatusLabel1).
Jetzt wird mit aus Form1.cs die Klasse in pinger.cs gestartet (als neuer Thread):
pinger.cs:
Hier der Aufruf:
Jetzt will ich bei //A und //B die Statusbar-Elemente ändern.
Dazu habe ich in Form1.cs folgende Methode:
Wenn ich jedoch jetzt versuche, in //A
aufzurufen und in //B das,
kommt es zu einem CS0120.
Was mache ich falsch?
probiere jetzt mal C# aus, habe nur ein Problem mit der (Sichtbarkeit?) der Unterklassen/Methoden in einer Form.
Form1.cs
enthält u.a. eine Statusleiste (toolStripProgressBar1, toolStripStatusLabel1).
Jetzt wird mit aus Form1.cs die Klasse in pinger.cs gestartet (als neuer Thread):
pinger.cs:
Code:
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Windows.Forms;
namespace idea
{
class pinger
{
private string host;
public pinger(string host_str)
{
host = host_str;
}
public void do_ping()
{
try
{
//A
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(host, timeout, buffer, options);
string message = "";
if (reply.Status == IPStatus.Success)
{
message += "Address: {0}" + reply.Address.ToString();
message += "\nRoundTrip time: {0}" + reply.RoundtripTime;
message += "\nTime to live: {0}" + reply.Optionsl;
message += "\nDon't fragment: {0}" + reply.Options.DontFragment;
message += "\nBuffer size: {0}" + reply.Buffer.Length;
}
System.Windows.Forms.MessageBox.Show(message);
}
catch
{
System.Windows.Forms.MessageBox.Show("PC aus.");
}
//B
System.Threading.Thread.CurrentThread.Abort();
}
}
}
Hier der Aufruf:
Code:
pinger tws = new pinger(e.Node.Text);
Thread t = new Thread(new ThreadStart(tws.do_ping));
t.Start();
Jetzt will ich bei //A und //B die Statusbar-Elemente ändern.
Dazu habe ich in Form1.cs folgende Methode:
Code:
public void statusbar(bool visible_progressbar, int progress, bool visible_label, string label_text)
{
toolStripProgressBar1.Visible = visible_progressbar;
toolStripProgressBar1.Value = progress;
toolStripStatusLabel1.Visible = visible_label;
toolStripStatusLabel1.Text = label_text;
}
Code:
Form1.statusbar(true,100,true,"Pinge Host...");
Code:
Form1.statusbar(false, 0, false, "");
Was mache ich falsch?