Events and multithreading for a Time Critical Application
<p>I have an application which works on a 10 ms cycle (every 10 ms all the functions are run so it almost behave like an embedded controller). There is a function in my code which is more expensive (in terms of execution time) than I want. This function is called <code>sendECSResponce</code> (This send a string to a Client via TCP/IP, I have not included the code). To get my application light I decoupled this function and put it in a different thread called <code>sendMessage</code>. I made a function which will throw an event called (this has been referred from an article, below is the code)</p>

<pre><code>public class EventThrower
{
    public delegate void EventHandler(object sender, EventArgs args);
    public event EventHandler ThrowEvent = delegate { };

    public void SomethingHappened()
    {
        ThrowEvent(this, new EventArgs());
    }
}
</code></pre>

<p>In access the event where I need (below is an example)</p>

<pre><code>public class SomeOtherClass
{
    private ATCom.Classes.EventThrower _Thrower = new ATCom.Classes.EventThrower();
    public void SendMessagetoECS()
    {
        string msg = Globals.gMessageForECS;
        //_Thrower = new EventThrower();
        //using lambda expression..could use method like other answers on here
        _Thrower.ThrowEvent += (sender, args) =&gt; { sendECSResponce(msg); };
    }

    public void localControl()
    {
        // Decalre ECS message
        Globals.gAllocRSPCode = AGV_Rsp_Code.C_ARC_OTHER_CONTROL;
        ECSMessage lclCntrl = new ECSMessage();
        lclCntrl.ID = MessageID.AT_LOCAL_CONTROL;
        lclCntrl.length = 0;
        // EVENT: Sending Message 
        _Thrower.EventThrower();
    }
}
</code></pre>

<p>In <code>localControl()</code> I throw an event to send the message via TCP/IP (<code>sendECSResponce(msg)</code>). 
Now I start a Thread and assign the function to the Thread in my main function. </p>

<pre><code>private void myMain()
    {
        System.Threading.Thread mainThread;
        System.Threading.Thread sendMessage;
        mainThread = new System.Threading.Thread(objectOfSomeClass.mainFunction);
        sendMessage = new System.Threading.Thread(objectOfSomeOtherClass.SendMessagetoECS);
        mainThread.Start();
        sendMessage.Start(); 
    }
</code></pre>

<p>The code is compiled but it does not do the needful. It does not send a message when <code>localControl()</code> is called in <code>mainThread</code>. Please help me with this. </p>