Reputation: 2912
A boolean variable is initialized as false in an assembly, but will become true at some point. How should I catch that in the main application which loads the assembly?
Someone says I should fire an event from assembly, then catch it in the main application. That sounds reasonable, but how? Or any other ways to do it? Thanks.!
I am asking for the idea, and some sample code. Thanks.
EDIT:
Like I said I have two separate instance, one is the assembly that will release some signal at some point, the other instance is main application that tries to catch the signal sent off by the assembly. So if there is some code, I need to know which instance the code belongs to.
Upvotes: 0
Views: 73
Reputation: 2247
An event could work something like this
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click( object sender, EventArgs e )
{
var logChecker = new Test();
logChecker.ChangedEvent += x => MessageBox.Show( "Value is " + x );
logChecker.Start();
}
}
internal class Test
{
private bool _property;
public Boolean Property
{
get { return _property; }
set
{
_property = value;
ChangedEvent( value );
}
}
public void Start()
{
var thread = new Thread( CheckLog );
thread.Start();
}
private void CheckLog()
{
var progress = 0;
while ( progress < 2000 )
{
Thread.Sleep( 250 );
progress += 250;
}
Property = true;
}
public event TestEventHandler ChangedEvent;
}
internal delegate void TestEventHandler( bool value );
Upvotes: 1