你需要处理的一些问题:
第一,不使用<代码> 阅读代码>类别。 确实如此。 除非你重写平行处理的框架,否则如果你重新使用<代码>Thread/,你几乎肯定会犯错。 采用System.Threading.Tasks.Task
或(如果在4.0之前重新采用System.Threading.ThreadPool
,以作为同义执行。
Second, you should be aware that sharing instance variables like data
between threads is sticky. You re much better off passing the data that you want to save to the async function so that there are no issues of contention or race conditions.
第三,如果是执行命令,你想要做些什么:
<things happen>
OnEvent fires
<things happen>
Serialize starts
OnEventFires
Serialize completes
自code>OnEvent fires in the summary of 以来,它是否完全忽视了它,或者它是否计划了另一个序列化? 如果你们在这里回答“b”的话,应该怎么做?
<things happen>
OnEvent fires
<things happen>
Serialize starts
OnEvent fires
<things happen>
OnEvent fires
Serialize completes
Should two calls to Serialize
be scheduled, or just one?