小编Mor*_*Cat的帖子

当原始类超出范围时,线程会发生什么

为了清楚起见,我简化了下面的例子,但我在现场制作程序中遇到了这个,我看不出它会如何工作!

public class Test
{
    static void Main() 
    {
        Counter foo = new Counter();
        ThreadStart job = new ThreadStart(foo.Count);
        Thread thread = new Thread(job);
        thread.Start();
        Console.WriteLine("Main terminated");
    }
}

public class Counter
{
    public void Count()
    {
        for (int i = 0; i < 10; i++)
        {
            Console.WriteLine("Other thread: {0}", i);
            Thread.Sleep(500);
        }
        Console.WriteLine("Counter terminated");
    }
}
Run Code Online (Sandbox Code Playgroud)

主程序启动计数器线程,主程序终止.无论给出以下输出,计数器线程都会继续运行.

Main terminated    
Other thread: 0
Other thread: 1
Other thread: 2
Other thread: 3
Other thread: 4
Other thread: 5   
Other thread: …
Run Code Online (Sandbox Code Playgroud)

.net c# multithreading

16
推荐指数
3
解决办法
2467
查看次数

manifest.json 显示属性具有无效的浏览器选项

文档似乎指出,manifest.json 中的“显示”属性有四个选项:全屏、独立、最小用户界面和浏览器

我决定为我的一个应用程序选择“浏览器”,但来自 Chrome(版本 76)的消息显示“清单‘显示’属性必须是‘独立’、‘全屏’或‘最小用户界面’之一”。如果我未定义“显示”,也会出现该消息。

“浏览器”是一个过时的选项还是它还没有进入最新的 Chrome 版本?

(我可能应该提到该消息出现在 Chrome DevTools>application>manifest 中)。

google-chrome-devtools progressive-web-apps manifest.json

8
推荐指数
1
解决办法
2130
查看次数

使用变量键名访问JSON项

以下是我的JSON数据,恰好是维基数据提供的格式,虽然为了清晰起见而大大减少了.

{
"entities": {
    "Q200405": {
        "id": "Q200405",
        "type": "item",
        "claims": "Cheese"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图在c#中访问这些数据.我的问题是Q200405是动态的 - 它基本上是我正在检索的记录号.例如,另一页可能会给我

{
"entities": {
    "Q123456": {
        "id": "Q123456",
        "type": "item",
        "claims": "Lemon"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我最好的尝试是使用Json.NET(Newtonsoft);

json = "{\"entities\":{\"Q200405\" {\"id\":\"Q200405\",\"type\":\"item\",\"claims\":\"Cheese\"}}}";

var Query = JsonConvert.DeserializeObject<dynamic>(json);
string entities = Query.entities.ToString();

Query = JsonConvert.DeserializeObject<dynamic>(entities);
string entity = Query.Q200405.ToString();

Query = JsonConvert.DeserializeObject<dynamic>(entity);
string id = Query.id.ToString();
string claims = Query.claims.ToString();
Run Code Online (Sandbox Code Playgroud)

可行,但显然硬编码Query.Q200405.ToString()不是理想的解决方案!我可能不应该做多个Deserialize语句来深入研究数据?

我的问题是将上述JSON格式读入ac#程序的最佳方法是什么?

c# mediawiki json wikidata wikidata-api

4
推荐指数
1
解决办法
3724
查看次数