【发布时间】:2017-10-04 14:20:27
【问题描述】:
我需要从不是第一个启动的进程中访问 GUI FORM 的完整属性和方法。
[MTAThread]
static void Main(string[] args)
{
//check if the app is already running
running = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Length > 1;
Console.WriteLine("ALready running? " + running);
if (running) // not first process
{
MessageBox.Show("Application already running in background!!!");
closing = false;
// HERE I NEED TO ACCESS TO gui-form defined by the first process and call some methods, modify properties ...
}
else { //first process
if (!closing)// there are no process active
{
string selected = null;
if (args.Length == 1) //apertura da context menu
{
selected = args[0];
pathSend = selected;
}
Console.WriteLine("ALready running: opening " + pathSend);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//create userManagerUnit
umu = new UserManagerUnit();
//create a ManualResetEvent used from Server's Threads
// true -> server start work || false -> server stop work
mre = new ManualResetEvent(true);
// create Server istance
// active server
server = new Server();
serverThread = new Thread(server.EntryPoint) { Name = "serverThread" };
serverThread.IsBackground = true;
serverThread.Start();
//create new client
client = new Client();
// create gui istance
gui = new GUI(selected);
//run application
Application.Run(gui);
}
}
}
我尝试过委托,但我无法委托存在于另一个进程中的某些内容。 我的应用程序是从 .exe/右键菜单(在文件/目录上)启动的 所以我可以启动它 N 次,每次我需要用不同的参数重新加载我的 gui,但我不需要创建 N gui,只需更新第一次创建的那个。 谢谢
【问题讨论】:
-
你要实现的是进程间通信,你能检查一下吗? stackoverflow.com/questions/84855/…
-
不是 Ian H。这与跨线程调用无关。
-
已解决!谢谢 Oguz Ozgul,我用过 MemoryMappedFile