How to share the same context with different threads in multi-Command Pattern in C#?
<p>There is an extended implementation of <strong>command pattern</strong> to support multi-commands (groups) in C#:   </p>

<pre><code>var ctx= //the context object I am sharing...

var commandGroup1 = new MultiItemCommand(ctx, new List&lt;ICommand&gt;
    {
        new Command1(ctx),
        new Command2(ctx)
    });

var commandGroup2 = new MultiItemCommand(ctx, new List&lt;ICommand&gt;
    {
        new Command3(ctx),
        new Command4(ctx)
    });

var groups = new MultiCommand(new List&lt;ICommand&gt;
    {   
        commandGroup1 ,
        commandGroup2 
    }, null);
</code></pre>

<p>Now , the execution is like:</p>

<pre><code>groups.Execute();
</code></pre>

<p>I am sharing the same <strong>context</strong> (ctx) object.</p>

<p>The execution plan of the web app needs to separate 
<code>commandGroup1</code> and <code>commandGroup2</code> groups in different thread. In specific, <code>commandGroup2</code> will be executed in a new thread and <code>commandGroup1</code> in the main thread.</p>

<p>Execution now looks like:</p>

<pre><code>//In Main Thread
commandGroup1.Execute();

//In the new Thread
commandGroup2.Execute();
</code></pre>

<p>How can I <strong>thread-safely</strong> share the same <code>context object (ctx)</code>, so as to be able to rollback the <code>commandGroup1</code> from the new Thread ?</p>

<p>Is  <code>t.Start(ctx);</code> enough or do I have to use lock or something?</p>

<p>Some code implementation example is <a href="https://gist.github.com/anonymous/3bb00077d497fc3bed872ae4fd5a420a">here</a></p>