我正在尝试按照此处提供的入门示例:https://components.xamarin.com/gettingstarted/facebookios
以下GraphRequest在主线程中执行时工作正常:
var request = new GraphRequest ("/me?fields=name", null, AccessToken.CurrentAccessToken.TokenString, null, "GET");
request.Start ((connection, result, error) => {
// Handle if something went wrong with the request
if (error != null) {
new UIAlertView ("Error...", error.Description, null, "Ok", null).Show ();
return;
}
// Get your profile name
var userInfo = result as NSDictionary;
nameLabel.Text = userInfo ["name"].ToString ();
});
但是,当我使用 Task.Run 从后台线程运行完全相同的代码时,似乎永远不会调用 request.Start 中的完成处理程序委托。 / p>
GraphRequest是否仅支持从主线程执行?
答案 0 :(得分:4)
您可以使用:
static void Main(string[] args)
{
Dictionary<int, string> test = new Dictionary<int, string>();
test.Add(1, "1");
test.Add(3, "3");
test.Add(4, "4");
test.Add(5, "5");
test.Add(2, "2");
JoinTest(test);
}
private static void JoinTest(Dictionary<int, string> test)
{
var keys = string.Join(",", test.Keys);
var values = string.Join(",", test.Values);
}