I have multiple actions running at the same time. When Action 1 is finished - it's followed up by Action Nr.2, then 3, then 1 or 9 or 9 again or 10 or 7... in random sequence.
I need to:
Store data which I get as the result of the Action/activity.
Retrieve This data when the same Action continues!
I can identify actions:
Here is how I imagine it:
Start program.
First step is to check if Data for new Activity exists - for that reason we grab ID and do the checking.
Since it's our new/first Action/Activity there isn't any past data, so by the end of the action we create and save new data into some kind of dynamic storage.
string[,] ID123 = new string[2, 3] { { "120", "200", "#ffc90e" }, { "380", "200", "#22b14c" } };
When Action 1 is finished, Action 2 starts, Practically, we do the same as what we did in p.3.
string[,] ID456789 = new string[2, 3] { { "10", "5", "#40" }, { "6", "8", "#80" } };
Now it's Activity 1 again! We identify it by the unique ID. This time, if we search for existing data- we will find this:
string[,] ID123 = new string[2, 3] { { "120", "200", "#ffc90e" }, { "380", "200", "#22b14c" } };
Now I do some editing + adding new values if needed. Continue.
One of the simplest solutions that I've thought of was - to simply create a temporary file with the "ID.txt" name. Unfortunatelly I'll be having up to 10-15 actions running at the same time so this approach won't be as fast as if I just recorded everything into memory.. The question is - how do I do it? sql? txt?
Some facts:
ID are always different for different Activities
I don't know precise Activity count (varies between 10 and 15)
I'll need to store an array type data, i.e.
string[,] array: 1, 15, 32, 12
2, 11, efg, 0
5, 9, 5, abc
...
similar question: Dynamic array in C#
there will be some conditions in my code that will trigger "data removal", actions have a lifespan ;)
It's unclear what you're trying to accomplish here, where and how actions enter this chain and how you need to deal with them.
As far as keeping track of what's currently in process, all you need is proper concurrency. There are several objects built into .NET 4.0 that you can use, or you can create your own. Since this data is dynamic, it probably shouldn't be persisted, unless you expect your process to be able to pick up exactly where it left off after being terminated. So, you could, for example, use a ConcurrentDictionary<string, string[,]>
that will store two-dimensional arrays, keyed by an ID string which must be unique within the Dictionary (even if the arrays of two IDs have the same dimensions and values). Concurrency-checking is built-in, meaning you can have multiple threads performing multiple actions against this Dictionary without worrying about "race conditions" where two threads may attempt to read or write the same thing at the same time.
Be aware that data in memory as part of your process will cease to exist when the process ends, for whatever reason. If you don't want that to happen, you can have a thread whose job it is to persist the ConcurrentDictionary's contents to a file or database. Since it's one thread, reading from a thread-safe collection of data, the problems of concurrencies in file writing are largely avoided AS LONG AS one record in the ConcurrentDictionary doesn't depend upon data in another (you can still deal with cases where one record does depend on another, but it gets more complex). This thread can be "kicked off" during the performance of other actions, or based on a Timer, or whatever you choose to meet your needs.