我尝试在某些PC上使用代码.
using (var lps = new LocalPrintServer())
using(var pqueue = lps.GetPrintQueue("PRINTER-NAME"))
{
pqueue.AddJob("job-name", @"C:\example.xps", false, pticket);
}
Run Code Online (Sandbox Code Playgroud)
仅在一台PC上,它不起作用.应用程序冻结了AddJob方法.它在等待很长时间后甚至没有完成.没有例外.
出现此问题的PC是Windows10并应用了CreatorsUpdate.其他PC是Windows7,Windows8.1和Windows10应用的AnniversaryUpdate.
这个问题是CreatorsUpdate的错误吗?
补充:
具有CreatorsUpdate的PC可以通过此代码打印xps文件.
using (var lps = new LocalPrintServer())
using(var pqueue = lps.GetPrintQueue("PRINTER-NAME"))
using (var doc = new XpsDocument(@"C:\example.xps", System.IO.FileAccess.Read))
{
var writer = PrintQueue.CreateXpsDocumentWriter(pqueue);
var docSeq = doc.GetFixedDocumentSequence();
writer.Write(doc, pticket);
}
Run Code Online (Sandbox Code Playgroud) 我想通过 CDN 使用这个库。
https://www.jsdelivr.com/package/npm/lit-element
我的js代码在这里。
import { LitElement, html } from "https://cdn.jsdelivr.net/npm/lit-element@2.1.0/lit-element.js";
class MyElement extends LitElement {
render(){
return html`ABCD`
}
}
customElements.define("my-element", MyElement)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误。
未捕获的类型错误:无法解析模块说明符“lit-html”。相对引用必须以“/”、“./”或“../”开头。
我必须使用 npm 构建吗?
以下代码有效。
import { LitElement, html } from "https://unpkg.com/lit-element/lit-element.js?module"
class MyElement extends LitElement {
render(){
return html`ABCD`
}
}
customElements.define("my-element", MyElement)
Run Code Online (Sandbox Code Playgroud) String.raw非常有用.例如:
let path = String.raw`C:\path\to\file.html`
Run Code Online (Sandbox Code Playgroud)
但是,当模板字符串的最后一个字符为时\,它将成为语法错误.
let path = String.raw`C:\path\to\directory\`
Run Code Online (Sandbox Code Playgroud)
未捕获的SyntaxError:未终止的模板文字
暂时,我使用这种方法.
let path = String.raw`C:\path\to\directory\ `.trimRight()
Run Code Online (Sandbox Code Playgroud)
我可以写最后一个字符\使用的模板字符串String.raw吗?
我想从另一个脚本标签导入。
<script type="module">
export default "str"
</script>
<script type="module">
import foo from "????"
console.log(foo) // str
</script>
Run Code Online (Sandbox Code Playgroud)
“???”里应该写什么?
我原以为读取文件等异步处理在其他线程上处理,在其他线程读完时通知主线程.
我试过跟随.
const fs = require("fs")
console.time(1)
fs.readFile("largefile", x => console.timeEnd(1))
Run Code Online (Sandbox Code Playgroud)
这表明1500ms.
其次我试着跟随.
const fs = require("fs")
console.time(1)
fs.readFile("largefile", x => console.timeEnd(1))
// block main thread 1sec
const s = Date.now()
while(Date.now() - s < 1000);
Run Code Online (Sandbox Code Playgroud)
它将显示1500ms是否在其他线程上处理异步进程.但是,我得到了2500ms.
我尝试了另一个.
const fs = require("fs")
console.time(1)
fs.readFile("largefile", x => console.timeEnd(1))
setInterval(() => {
const s = Date.now()
while(Date.now() - s < 100);
}, 100)
Run Code Online (Sandbox Code Playgroud)
我等了几分钟,但没有消息.
nodejs是否在主线程上处理繁重的处理?
child_process当我需要读取和写入太多大文件时,我应该使用吗?
我想从 Rust 程序运行此命令:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://stackoverflow.com/"
Run Code Online (Sandbox Code Playgroud)
在cmd中,这是有效的。
cmd /C ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://stackoverflow.com/""
Run Code Online (Sandbox Code Playgroud)
在 C# 中,这是可行的。
var comm = @"""""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""https://stackoverflow.com/""""";
System.Diagnostics.Process.Start("cmd", "/C " + comm);
Run Code Online (Sandbox Code Playgroud)
在 Rust 中,这是行不通的。
let comm = r#"""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://stackoverflow.com/"""#;
let output = Command::new("cmd")
.args(&["/C", comm])
.output()
.expect("failed to execute process");
Run Code Online (Sandbox Code Playgroud)
我收到以下错误。
var comm = @"""""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""https://stackoverflow.com/""""";
System.Diagnostics.Process.Start("cmd", "/C " + comm);
Run Code Online (Sandbox Code Playgroud)
但是,它comm在时有效echo hello。
我尝试了另外两种方法:
这
let comm = r#"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe https://stackoverflow.com/"#;
Run Code Online (Sandbox Code Playgroud)
是
let …Run Code Online (Sandbox Code Playgroud)在trim_right_matches我可以传递一个字符串值:
println!("{}", "[(foo)]".trim_right_matches(")]"));
// [(foo
Run Code Online (Sandbox Code Playgroud)
但是,我不能在trim_matches以下字符串中使用字符串值:
println!("{}", "[(foo)]".trim_matches("[()]"));
Run Code Online (Sandbox Code Playgroud)
因为我收到以下错误:
error[E0277]: the trait bound `std::str::pattern::StrSearcher<'_, '_>: std::str::pattern::DoubleEndedSearcher<'_>` is not satisfied
--> test.rs:2:27
|
2 | println!("{}", "[(foo)]".trim_matches("[()]"));
| ^^^^^^^^^^^^ the trait `std::str::pattern::DoubleEndedSearcher<'_>` is not implemented for `std::str::pattern::StrSearcher<'_, '_>`
error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)
以下代码有效:
println!("{}", "[(foo)]".trim_matches(&['(', '[', ']', ')'] as &[_]));
// foo
Run Code Online (Sandbox Code Playgroud)
但是,它很长并且不像单个字符串值那样容易阅读; 我希望能够使用类似的字符串值trim_right_matches.
javascript ×4
es6-modules ×2
rust ×2
.net ×1
asynchronous ×1
c# ×1
cdn ×1
html ×1
lit-element ×1
node.js ×1
printing ×1
string ×1
windows ×1
windows-10 ×1