是否可以将 BackgroundWorker 类与 .net core 一起使用? [英] Is it possible to use BackgroundWorker class with .net core?

查看:32
本文介绍了是否可以将 BackgroundWorker 类与 .net core 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将在 Windows 上运行良好的 C# 控制台项目移植到带有 .NET Core 的 Linux.我创建了一个 project.json 文件,运行 dotnet restore,一切似乎都正常.但是当我运行 dotnet build 时,我收到此消息:

I am trying to port a C# console project that works fine on Windows to Linux with .NET Core. I have created a project.json file, run dotnet restore and everything seems to work fine. But when I run dotnet build, I get this message :

找不到类型或命名空间名称BackgroundWorker"(是您是否缺少 using 指令或程序集引用?)

The type or namespace name 'BackgroundWorker' could not be found (are you missing a using directive or an assembly reference?)

根据 .NET Core API,System.ComponentModel 中似乎存在类 BackgroundWorker.

According to .NET Core API, the class BackgroundWorker seems to exist in System.ComponentModel.

这是我的 project.json :

Here's my project.json :

"version": "1.0.0-*",
  "buildOptions": {
  "debugType": "portable",
  "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  }

我错过了什么吗?

谢谢!

推荐答案

您需要包含 System.ComponentModel.EventBasedAsync nuget 包作为依赖项(而不是 System.ComponentModel代码> nuget 包).如果您查看 GitHub 上的 BackgroundWorker.cs 文件,可以看到它嵌套在 System.ComponentModel.EventBasedAsync 命名空间下.

You need to include the System.ComponentModel.EventBasedAsync nuget package as a dependency (not the System.ComponentModel nuget package). If you look at the BackgroundWorker.cs file on GitHub, you can see that it's nested under the System.ComponentModel.EventBasedAsync namespace.

您的 project.json 将如下所示:

Your project.json would look like this:

  "version": "1.0.0-*",
  "buildOptions": {
  "debugType": "portable",
  "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        },
        "System.ComponentModel.EventBasedAsync": "4.3.0"
      },
      "imports": "dnxcore50"
    }
  }

这篇关于是否可以将 BackgroundWorker 类与 .net core 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆