【发布时间】:2016-09-29 13:42:39
【问题描述】:
我对编程还很陌生, 很抱歉,如果我把一些词搞砸了,我想这个问题可能真的很愚蠢。
无论如何,我正在尝试从不同的线程控制 C# 浏览器窗口。
该程序有 2 个窗口。控制台和带有浏览器窗口的表单。
namespace CodeSnippet
{
public partial class browserwindow : Form
{
public browserwindow()
{
InitializeComponent();
//for the browser form to open, the console HAS to run in a seperate thread
Thread ConsoleThread = new Thread(new ThreadStart(TheConsole));
ConsoleThread.Start();
}
public static void TheConsole()
{
while(true)
{
//read the input
string rawinput = Console.ReadLine();
string input = rawinput.ToLower();
//look for commands
if(input == "website")
{
Console.WriteLine("Waiting...");
string website = Console.ReadLine();
//TheBrowser is the name of the browser window
TheBrowser.Navigate(website);
Console.WriteLine("done!");
}
}
}
“TheBrowser.Navigate”在这段代码中不起作用。 但是,如果我删除“TheConsole()”上的“静态”,代码就可以正常工作了。
现在我的问题是:从函数中删除静态是否“可以”?p>
【问题讨论】:
-
“从函数中删除静态是否'可以'” - see the difference
-
多线程对于初学者来说不是一个好话题。有很多微妙之处。为了解决您的具体问题:您的问题是“我要对我不理解的程序进行更改,可以吗?”不。在进行更改之前了解更改。然后进行更改。
标签: c# multithreading static