One thing that has always confused me is how BackgroundWorker seems to have thread-safe access to instance variables of the surrounding class.
Given the base class:
public class BackgroundProcessor { public List<int> Items { get; private set; } public BackgroundProcessor(IEnumerable<int> items) { Items = new List<int>(items); } public void DoWork() { BackgroundWorker worker = new BackgroundWorker(); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerAsync(); } void worker_DoWork(object sender, DoWorkEventArgs e) { var processor = new ProcessingClass(); processor.Process(this.Items); //Accessing the instance variable } void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //Stuff goes here } }
Am I mistaken in my assumption that the call processor.Process(this.Points);is a thread-safe call? How can I get cross flow access violation?
processor.Process(this.Points);
I'm sure this is obvious, but it always confused me.
-, . . , , . , . , ( , , USER), .
- , . - . , . , , , , , , . , , , .
- , .
, , .
Source: https://habr.com/ru/post/1781385/More articles:приоритет операторов в C - cAdobe Reader process does not work when starting the second instance - c #How to stop the Selenium server from an Ant task that I forked for the purpose of "java"? - javaC ++ 0x: How can I access variable set members by index at runtime? - c ++Выберите подмножество элементов внешнего ключа inlineformset_factory в Django - djangoПоддерживает ли Netbeans версию 6.9.1 плагин SOA? - javaProgrammatically push data to Quickbooks Online? - apiProblems with NetworkManager and Qt - c ++how can I make a dropdown menu in jQuery - jqueryОтображение NHibernate для базы данных Oracle вызывает StaleStateException - oracleAll Articles