我正在为其中一个游戏写一个简单的“查询计数器英雄” - 更多的是培训而不是开发。
我有12个正在更新全局变量的任务。这些任务涉及读取和反序列化一个小JSON文件(大约900字节),并将一些结果写入全局变量。有趣的是它在HyperV Windows Phone模拟器上运行得非常好并且稳定,而当加载到设备时,它总是在行'System.NullReferenceException'
与CountersHI1.HeroImage = Counters1.IMGurl;
崩溃我相信这可能是由于HyperV WP的事实线程比物理手机快得多。我试着等待所有任务完成,但也许我做错了什么?此外,innerException
对我来说很困惑:
error CS0012: The type 'Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
我已经接近不知道为什么它没有看到我的“使用”或问题很可能在其他地方。任何帮助非常感谢,在违规代码之下。如果您需要更多详细信息,请告诉我们!
如果重要,我正在使用VS 2015社区。
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
Herodata hero = JsonConvert.DeserializeObject<Herodata>(fileContent);
HeroInformation0.HeroImage = hero.IMGurl;
HeroInformation0.HeroName = hero.Heroname;
Task[] tasks = new Task[12];
tasks[0] = new Task(() => UpdateCounteredHI1(hero.Counteredby[0]));
tasks[1] = new Task(() => UpdateCounteredHI2(hero.Counteredby[1]));
tasks[2] = new Task(() => UpdateCounteredHI3(hero.Counteredby[2]));
tasks[3] = new Task(() => UpdateCounteredHI4(hero.Counteredby[3]));
tasks[4] = new Task(() => UpdateCounteredHI5(hero.Counteredby[4]));
tasks[5] = new Task(() => UpdateCounteredHI6(hero.Counteredby[5]));
tasks[6] = new Task(() => UpdateCountersHI1(hero.Counters[0]));
tasks[7] = new Task(() => UpdateCountersHI2(hero.Counters[1]));
tasks[8] = new Task(() => UpdateCountersHI3(hero.Counters[2]));
tasks[9] = new Task(() => UpdateCountersHI4(hero.Counters[3]));
tasks[10] = new Task(() => UpdateCountersHI5(hero.Counters[4]));
tasks[11] = new Task(() => UpdateCountersHI6(hero.Counters[5]));
foreach (var task in tasks) { task.Start(); }
Task.WaitAll(tasks);
CountersHI1.HeroImage = Counters1.IMGurl;
CountersHI1.HeroName = Counters1.Heroname;
CountersHI2.HeroImage = Counters2.IMGurl;
CountersHI2.HeroName = Counters2.Heroname;
CountersHI3.HeroImage = Counters3.IMGurl;
CountersHI3.HeroName = Counters3.Heroname;
CountersHI4.HeroImage = Counters4.IMGurl;
CountersHI4.HeroName = Counters4.Heroname;
CountersHI5.HeroImage = Counters5.IMGurl;
CountersHI5.HeroName = Counters5.Heroname;
CountersHI6.HeroImage = Counters6.IMGurl;
CountersHI6.HeroName = Counters6.Heroname;
CounteredHI1.HeroImage = Countered1.IMGurl;
CounteredHI1.HeroName = Countered1.Heroname;
CounteredHI2.HeroImage = Countered2.IMGurl;
CounteredHI2.HeroName = Countered2.Heroname;
CounteredHI3.HeroImage = Countered3.IMGurl;
CounteredHI3.HeroName = Countered3.Heroname;
CounteredHI4.HeroImage = Countered4.IMGurl;
CounteredHI4.HeroName = Countered4.Heroname;
CounteredHI5.HeroImage = Countered5.IMGurl;
CounteredHI5.HeroName = Countered5.Heroname;
CounteredHI6.HeroImage = Countered6.IMGurl;
CounteredHI6.HeroName = Countered6.Heroname;
HeroInformation0.Visibility = Visibility.Visible;
CountersTB.Visibility = Visibility.Visible;
CounteredTB.Visibility = Visibility.Visible;
HeroInformation0.UpdateLayout();
});