c# - 如何在 UI 线程中读取文件
问题描述
我有这样的代码,但是当我运行它时显示“:
不应在 UI 线程上执行同步操作。考虑将此方法包装在 Task.Run 中
我该如何解决这个问题?谢谢
public guchi()
{
string[] list = File.ReadAllLines(@"C:\Users\sample.csv");
foreach (string item in list)
{
var tmp = item.Split(';');
this.Add(new guchi()
{
test = tmp[0],
fun = tmp[1],
happy = tmp[2],
run = tmp[3],
now = tmp[4],
god = tmp[5],
time = tmp[6],
final= tmp[7],
Pyke = tmp[8],
Xinzhao = tmp[9]
});
}
}
解决方案
推荐阅读
- youtube - 为什么 Google 不为其产品(如 google.com、youtube.com)使用 PWA 功能
- javascript - 使用对象过滤对象数组驻留在嵌套数组属性中
- asp.net-core - 升级到 ASP.NET Core 3.0 后,我得到“无法创建 stdoutLogFile 错误代码 = -2147024893”。
- powerbi - 是否有一个公式可以自动将数据从多列拖到新列中?
- arrays - 按类型对结构数组进行排序,然后按另一个属性按字母顺序排序
- android - 本地网络上的 Youtube Cast 按钮 Android
- python - 从给定范围python中查找所有素数
- bash - 区分用户注销和会话过期注销(SSH 和 Web 控制台)
- php - How to run laravel websocket on heroku
- javascript - Using new window instead of web-workers