0
您好,我知道我们可以用C#这样的区别返回任务
Task t1 = new Task(new Action(A))
运行任务,但一个是静态函数
我们可以有非静态函数,当我们有函数返回任务 可我们已经运行像
new Task(new Action(A));
,如果我们不能什么是DEF之间
static void A()
{
Console.Write("task");
}
Task t1 = new Task(new Action(A));
和
public async Task<BitmapImage> Set_Image(string location_in_server, string location_to_save, string name_file)
{
Ntaban.Api.API_HttpClient apic = new Ntaban.Api.API_HttpClient();
string location = location_to_save + name_file;
string location_directory = location_to_save;
if (Directory.Exists(location_directory) == false)
{
Directory.CreateDirectory(location_directory);
}
if (File.Exists(location) == false)
{
await apic.download_file_async(location_in_server + name_file, location, null);
}
BitmapImage s1 = new BitmapImage();
s1.BeginInit();
s1.UriSource = new System.Uri(location_to_save + name_file);
s1.EndInit();
return s1;
}
imgProfile.Source = savefile.Set_Image(Ntaban.Api.API_server.Host + "/content/profile/", St_Major.Directories.Directory_Main, lst.First().picAdr).Result;
我知道这个,但是当我们有函数返回任务(例如)它作为任务运行。 换句话说,我喜欢在任务或线程或CPU的其他核心运行我的功能我们该怎么办? –
@amirjahany:如果你想在一个线程池上运行代码,那么使用'Task.Run'。 –
感谢您的回答。你可以告诉我关于threadpool我不明白它 –