|
//
// PlugWithEvent
//
// sample splugin containing a class implementing 'IPlugInterface'
// and generating event callbacks
//
using System;
using System.Threading;
using MultiPlug.PlugInterface;
namespace MultiPlug.PlugWithEvent
{
public class WithEventClass : MarshalByRefObject, IPlugInterface
{
public WithEventClass( string initString )
{
baseText = "WithEventClass: " + initString;
}
public void Dispose()
{
StopThread();
}
public string ModifyString( string inpString )
{
return baseText + " @ " + inpString;
}
public string CurrentText
{
get { return baseText; }
set { baseText = value; }
}
public bool StartThread( IPlugEvent eventCallback )
{
this.eventCallback = eventCallback;
if( workthread != null )
return false;
ThreadStart ts = new ThreadStart( this.ThreadMethod );
workthread = new Thread( ts );
workthread.Name = "WORKER " + this.GetHashCode().ToString();
workthread.Start();
return true;
}
public void StopThread()
{
if( workthread != null )
{
workthread.Abort(); // brute force...
workthread.Join();
workthread = null;
}
eventCallback = null;
}
/// <summary> Thread start entry point </summary>
private void ThreadMethod()
{
Thread.CurrentThread.ApartmentState = ApartmentState.MTA;
Thread.CurrentThread.IsBackground = true;
int hint = 0;
do
{
Thread.Sleep( 1000 );
eventCallback.PlugNotification( hint++ );
}
while( true );
}
private string baseText;
private IPlugEvent eventCallback;
private Thread workthread;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.