小编Mr.*_*.AF的帖子

何时应将AllowSynchronousContinuations 选项与通道一起使用?

我正在 Asp Net Core 应用程序中实现简单的后台作业队列。我创建了它在幕后BackgroundJobQueue使用来排队将通过 处理的项目。阅读文档我偶然发现了通道的ChannelOptions.AllowSynchronousContinuations设置。BoundedChannel<T>HostedService

根据msdn的描述说:

将此选项设置为 true 可以通过避免安排额外的工作项目来提供可测量的吞吐量改进。然而,这可能会以减少并行性为代价,例如生产者可能是执行与消费者相关的工作的人,如果不深思熟虑,这可能会导致意外的交互。默认为 false。

我不太明白true在我的情况下设置此选项是否是一个好的选择。有人可以解释+提供这个选项何时有用/无用/有害的例子吗?

编辑

我得到的解释:

根据官方的说法,当生产者依赖于消费者时,它会等待消费者的工作完成然后开始工作,如果启用该选项,生产者会经历更多的空闲时间。但是,如果禁用该选项,由于并行性,生产者的空闲时间会减少。

启用选项不是很糟糕吗?由于 api 请求将需要更长的时间来处理,因为生产者将保持空闲的时间更长。为了澄清我的意思。假设我想在我的控制器中排队后台作业

public async Task<IActionResult> Action()
{
    // some code
   await _backgroundJobQueue(() => ....);
   return Ok();
}
Run Code Online (Sandbox Code Playgroud)

如果启用选项,那么生产者会经历更多的空闲时间,因此执行操作需要更长的时间?

c# asp.net-core asp.net-core-hosted-services

7
推荐指数
1
解决办法
859
查看次数

Gson.toJson 返回 null [ProGuard 问题]

用户错误报告显示Gson().toJson(obj)偶尔返回,{}但对于大多数用户来说它工作正常。

我访问了一个用户,他在手机上遇到了错误并调试了应用程序,我制作Toast了显示发送到服务器的内容,我看到了 Toast 显示{},并且记录ID也没有显示null

这是我所做的。

private class ClassA{
        String ID;
        ArrayList<ClassB> Records;

        ClassA(String ID, ArrayList<ClassB> Records) {
            this.ID= ID;
            this.Records= Records;
        }
 }

 private class ClassB {
        int T;
        int F;
        String D;

        ClassB (int T, int F, String D) {
            this.T= T;
            this.F = F;
            this.D= D;
        }

}
Run Code Online (Sandbox Code Playgroud)

在这里我做序列化对象

ClassA obj = new ClassA(ID,Records); 
String json = new Gson().toJson(obj);
Run Code Online (Sandbox Code Playgroud)

但是new Gson().toJson(obj)对于某些用户来说是正确的,但对于某些回报{} …

java android json gson

6
推荐指数
1
解决办法
1871
查看次数

ASP.NET - 如何通过 Web.config [CORS 策略问题] 从 HTTP 重定向到 HTTPS 和特定来源

我确实通过以下配置将用户重定向HttpHttps

<rewrite>
  <rules>
    <rule name="HTTP_TO_HTTPS" enabled="true" stopProcessing="true">
      <match url="(.*)"/>
      <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="^OFF$"/>
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false"/>
    </rule>
  </rules>
</rewrite>       
Run Code Online (Sandbox Code Playgroud)

它按预期工作。这里有一个问题,它只重定向到Https但不重定向到原点。我的意思是

http://www.example.comhttps://www.example.com

http://example.comhttps://example.com

以上情况造成的,用户认为Cross-origin resource sharing (CORS) policy问题的根源各不相同。

我想将所有用户重定向到https://example.com以避免冲突的来源。

asp.net https redirect cors

5
推荐指数
1
解决办法
299
查看次数

vue 3 + vuetify 3:Array.map 节点创建中的未知节点类型(&lt;anonymous&gt;)

我正在从vue2迁移到vue3以及vuetify 3。但是,我无法正确设置 vuetify 3。我收到以下错误

语法错误:错误:Array.map 节点创建中的节点类型未知(匿名)

在以下几行中:

in ./node_modules/vuetify/lib/components/VList/VListItem.css
in ./node_modules/vuetify/lib/components/VCard/VCard.css
in ./node_modules/vuetify/lib/components/VBtn/VBtn.css
Run Code Online (Sandbox Code Playgroud)

我尝试通过以下链接修复它

[错误报告][3.0.0-alpha.0] Vuetify 3“节点创建中的未知节点类型”错误#14179

vuetify-loader

但没有成功。

vuetify.js:

// Styles
import "@mdi/font/css/materialdesignicons.css";
import "vuetify/styles";
import colors from "vuetify/lib/util/colors";

// Vuetify
import { createVuetify } from "vuetify";

    export default createVuetify({
      theme: {
        themes: {
          options: { customProperties: true },
          light: {
            primary: "#FF6D00",
          },
          dark: {
            primary: "#FFCA28",
          },
        },
      },
      icons: {
        iconfont: "mdi", 
      },
    });
Run Code Online (Sandbox Code Playgroud)

main.js:

const app = …
Run Code Online (Sandbox Code Playgroud)

vue.js vuetify.js vuejs3

3
推荐指数
1
解决办法
2811
查看次数

如何在初始组合期间从可组合函数中的远程 API 调用/获取数据 [防止无限重组]

在下面的代码中:

@Composable
fun Device(contentPadding: PaddingValues, modifier: Modifier = Modifier) {
    val vm:DeviceList = viewModel()
    vm.getDevices()
    var devices = vm.uiState.collectAsState();

    LazyColumn(contentPadding = contentPadding) {
        items(devices.value) { device -> DeviceItem(device) }
    }
}
Run Code Online (Sandbox Code Playgroud)

调用vm.getDevices()远程 API 并获取 中所述的设备vm.uiState

问题

正如代码清楚显示的那样,它会导致无限的 UI 重组。更新状态和导致 UI 重组的vm.getDevices()新状态。vm.uiState结果,vm.getDevices()被调用并再次更新状态。

我在寻找什么

我想要一个推荐的解决方案(最佳实践)。此外,我可以放置一些脏代码,例如 if/else 条件,以防止无限的 UI 重组。但是,我认为对于此类问题有更好的干净解决方案。

编辑

class DeviceList : ViewModel() {

    private var deviceListUIState: MutableStateFlow<List<Device>> = MutableStateFlow(
        listOf()
    )

    val uiState
        get() = deviceListUIState.asStateFlow()

    fun getDevices() {
        viewModelScope.launch …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-jetpack-compose

3
推荐指数
1
解决办法
422
查看次数

ssh2:模块解析失败:意外字符“?”

ERROR in ./node_modules/cpu-features/build/Release/cpufeatures.node 1:2\nModule parse failed: Unexpected character \'\xef\xbf\xbd\' (1:2)\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders\n(Source code omitted for this binary file)\n @ ./node_modules/cpu-features/lib/index.js 3:16-60\n @ ./node_modules/ssh2/lib/protocol/constants.js 7:12-35\n @ ./node_modules/ssh2/lib/server.js 26:4-38\n @ ./node_modules/ssh2/lib/index.js 33:10-32\n @ ./src/app.js 3:19-34\n\nERROR in ./node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node 1:2\nModule parse failed: Unexpected character \'\xef\xbf\xbd\' (1:2)\nYou may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. …
Run Code Online (Sandbox Code Playgroud)

javascript commonjs node.js webpack

2
推荐指数
1
解决办法
1008
查看次数

快速/优雅的方法来查找List &lt;keys&gt;中不存在的字典键

我有一本字典A,我想以int快速适当的方式查找B中未列出的键。

Dictionary<int,object> A;

List<int> B;
Run Code Online (Sandbox Code Playgroud)

我想要

A KEYS ARE NOT EXISTING IN B

有没有一种快速而优雅的方法呢?

c# dictionary

-1
推荐指数
1
解决办法
77
查看次数