小さなアプリケーションを作成しましたが、リストボックスで表示できる何らかのタイプのログを組み込みたいと考えています。データのソースは、任意の数の場所から送信できます。デリゲートを渡す新しいログ クラスを作成しました。私は解決策に近づいていると思いますが、NullReferenceException を受け取っており、適切な解決策がわかりません。これが私がやろうとしていることの例です:
Class1 where the inbound streaming data is received.
class myClass
{
OtherClass otherClass = new OtherClass();
otherClass.SendSomeText(myString);
}
ロギング クラス
class OtherClass
{
public delegate void TextToBox(string s);
TextToBox textToBox;
Public OtherClass()
{
}
public OtherClass(TextToBox ttb)
{
textToBox = ttb;
}
public void SendSomeText(string foo)
{
textToBox(foo);
}
}
フォーム
public partial class MainForm : Form
{
OtherClass otherClass;
public MainForm()
{
InitializeComponent();
otherClass = new OtherClass(this.TextToBox);
}
public void TextToBox(string pString)
{
listBox1.Items.Add(pString);
}
}
myClass でデータを受け取るたびに、エラーがスローされます。あなたが与えることができる任意の助けをいただければ幸いです。