Вход на сайт
ThreadStatic - уперся не пойму во что...
226 просмотров
Перейти к просмотру всей ветки
в ответ Murr_0002 06.10.17 11:10
тут видно сразу несколько проблем:
-поток не может быть закончен когда потребуется
-паралельные потоки не должны быть зависимы один от другого
protected override void DoWork(object sender, DoWorkEventArgs e) { // none of params can be passed - only default constructor available T1 t1 = new T1(); // this is the only point where assigment can be done t1.GenerationEnvironment = _myThreadInstance; // generate output by T1 & T2 (as it called in T1) string text = t1.TransformText(); // in real world, unfortunetly, I need an option to write generated // text to file after T2 generation complete, but before T1 will finish // his work. }
А что мешает сделать TestInteractionT1 и TestInteractionT2 + синхронизация?
Хотя синхронизация будет чисто по времени записи.
ManualResetEvent sync = new ManualResetEvent(false);
StringBuilder myThreadInstance = ...
T1 t1 = new T1();
t1.GenerationEnvironment = myThreadInstance;
t1Thread = new TestInteractionT1(t1,myThreadInstance,sync);
T2 t2 = new T2();
t2.GenerationEnvironment = myThreadInstance;
t2Thread = new TestInteractionT2(t2,myThreadInstance,sync);
t1Thread.Start();
t2Thread.Start();