Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 创建(MSDN示例)_C#_Silverlight - Fatal编程技术网

C# 创建(MSDN示例)

C# 创建(MSDN示例),c#,silverlight,C#,Silverlight,我尝试为json创建一个简单的webrequest,我尝试使用MSDN上的示例 // Create a new 'Uri' object with the specified string. Uri myUri =new Uri("http://www.contoso.com"); // Create a new request to the above mentioned URL. WebRequest myWebRequest= WebReq

我尝试为json创建一个简单的webrequest,我尝试使用MSDN上的示例

// Create a new 'Uri' object with the specified string.
        Uri myUri =new Uri("http://www.contoso.com");
        // Create a new request to the above mentioned URL. 
        WebRequest myWebRequest= WebRequest.Create(**myUri**);
        // Assign the response object of 'WebRequest' to a 'WebResponse' variable.
        WebResponse myWebResponse= **myWebRequest**.GetResponse();
我得到以下错误

字段初始值设定项不能引用非静态字段、方法或属性

在高亮显示的对象上。(myUri和myWebRequest)有什么想法吗


谢谢,这不起作用,因为Silverlight中的所有内容都必须是异步的。它们强制执行此操作,因为主线程上的所有执行(如webrequest)都会锁定UI。这种方法提供了更好的用户体验,是让开发人员掌握线程在基本开发活动中的使用的一种折衷方法

见此: