我正在 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)
如果启用选项,那么生产者会经历更多的空闲时间,因此执行操作需要更长的时间?
用户错误报告显示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)对于某些用户来说是正确的,但对于某些回报{} …
我确实通过以下配置将用户重定向Http到Https
<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.com 到 https://www.example.com
http://example.com 到 https://example.com
以上情况造成的,用户认为Cross-origin resource sharing (CORS) policy问题的根源各不相同。
我想将所有用户重定向到https://example.com以避免冲突的来源。
我正在从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.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) 在下面的代码中:
@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) 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) 我有一本字典A,我想以int快速适当的方式查找B中未列出的键。
Dictionary<int,object> A;
List<int> B;
Run Code Online (Sandbox Code Playgroud)
我想要
A KEYS ARE NOT EXISTING IN B
有没有一种快速而优雅的方法呢?
android ×2
c# ×2
asp.net ×1
asp.net-core ×1
asp.net-core-hosted-services ×1
commonjs ×1
cors ×1
dictionary ×1
gson ×1
https ×1
java ×1
javascript ×1
json ×1
kotlin ×1
node.js ×1
redirect ×1
vue.js ×1
vuejs3 ×1
vuetify.js ×1
webpack ×1