0
如何將數據設置爲新創建的AppDomain。當我DoCallBack到我的testFunc我收到「System.NullReferenceException」異常。我做錯了什麼?如何將數據設置爲新的AppDomain
var client = "test";
var engine = 123;
AppDomain appDomain = AppDomain.CreateDomain("newDomain");
appDomain.SetData("client", client);
appDomain.SetData("engine", engine);
appDomain.DoCallBack(testFunc);
private void testFunc()
{
var client = (string)AppDomain.CurrentDomain.GetData("client");
var engine = (int)AppDomain.CurrentDomain.GetData("engine");
Console.WriteLine("client: " + client);
Console.WriteLine("engine: " + engine);
}
爲AppDomain設置vars globaly不會改變anathing,同樣的錯誤。
AppDomain.CurrentDomain.SetData("client", client);
AppDomain.CurrentDomain.SetData("engine", engine);
附: 我收到System.NullReferenceException,因爲AppDomain無法找到我在DoCallBack之前設置的變量。那麼如何正確設置它們呢?
的【什麼是一個NullReferenceException可能的複製,以及如何解決它?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Nasreddine
不,這不是。 – SLI
我已經創建了一個控制檯應用程序,複製了提供的代碼,並且所有內容都按照您的預期工作。 – Kzrystof