我该如何在控制台应用程序中读取用户输入、处理COM事件并从用户输入中调用COM对象的某些函数?
我正在尝试整合以下内容:
static void Main(string[] args)
{
// Read user input
string input;
do
{
// Start thread for com here??
input = Console.ReadLine();
if (input == "Function1")
{
// Call Function1 on Com object
}
if (input == "Function2")
{
// Call Function2 on Com object
}
} while (input != null);
// Exit app
}
--
// Call com on separate thread
Thread thread = new Thread(MessagePumpThread);
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
--
void MessagePumpThread()
{
var activex = new activeXObject();
activex.CreateControl();
// Subscribe to events...
Application.Run();
}
我想在控制台中完成类似于Windows窗体应用程序中容易实现的功能。
非常感谢您的帮助,谢谢。