我不知道这是错误还是错误?在代码虚拟化后返回空值。
[assembly: Obfuscation(Feature = "Apply to type *: apply to member * when method or constructor: virtualization", Exclude = false)]
namespace ConsoleApp17
{
class Program
{
private static bool valueWritten = false;
private static int sharedValue = 0;
private static void ThreadOneStart()
{
sharedValue = 1000;
valueWritten = true;
}
private static void ThreadTwoStart()
{
if (valueWritten) Console.Write(sharedValue == 1000 ? "Good" : "Bad");
}
static void Main(string[] args)
{
Thread threadOne = new Thread(ThreadOneStart);
Thread threadTwo = new Thread(ThreadTwoStart);
threadOne.Start();
threadTwo.Start();
threadOne.Join();
threadTwo.Join();
Console.ReadKey();
}
}
}
答案 0 :(得分:0)
给定程序具有竞争条件。这意味着程序行为是不确定的。与Eazfuscator.NET无关。
这是正确的方法:
[assembly: Obfuscation(Feature = "Apply to type *: apply to member * when method or constructor: virtualization", Exclude = false)]
class Program
{
private static bool valueWritten = false;
private static int sharedValue = 0;
private static ManualResetEvent ev = new ManualResetEvent(false);
private static void ThreadOneStart()
{
sharedValue = 1000;
valueWritten = true;
ev.Set();
}
private static void ThreadTwoStart()
{
ev.WaitOne();
if (valueWritten) Console.Write(sharedValue == 1000 ? "Good" : "Bad");
}
static void Main(string[] args)
{
Thread threadOne = new Thread(ThreadOneStart);
Thread threadTwo = new Thread(ThreadTwoStart);
threadOne.Start();
threadTwo.Start();
threadOne.Join();
threadTwo.Join();
Console.ReadKey();
}
}