for two concurrent threads to update the same Dictionary you need to use locks, or the concurrent dictionary:
also in your example, the main thread blocks until the background thread completes, so there is no advantage to background thread except to implement the timeout. but you fail to kill the background thread on the timeout, so not clear the use case.
simpler code:
var MyOwnData = new SortedDictionary<int, OwnData>
{
{index, new OwnData()}
};
var thread = Thread.Run(() =>
{
DoIt();
// technically lock not needed because only 1 thread running.
lock(MyOwnData)
{
MyOwnData.Add(3, new OwnData());
}
});
if (!thread.Wait(10000))
{
thread.Abort();
throw new Exception(TIMEOUT__PROGRAM);
}