问题
This one has me a bit perplexed. I have a Shown event for a form, but the event's implementation doesn't process unless I display a MessageBox.
Here is my code which does not work:
private void MainForm_Shown(object sender, EventArgs e)
{
string[] arguments = Environment.GetCommandLineArgs();
foreach (var argument in arguments)
{
if (argument == "someArgs")
{
var something = doSomeStuff();
}
}
}
Whenever I add a message box like this though, it works:
private void MainForm_Shown(object sender, EventArgs e)
{
string[] arguments = Environment.GetCommandLineArgs();
foreach (var argument in arguments)
{
if (argument == "someArgs")
{
var something = doSomeSuff();
}
else
{
MessageBox.Show(argument);
}
}
}
I have tried using both a Form_Load and Form_Activated event, but they both cause my program to crash entirely do to the implementation in doSomeStuff
.
Just a little background of how this program works. I'm trying to establish a WCF connection. I have already successfully done this with some hard-coded values, but I'm trying to make it dynamic via the doSomeStuff
method. I believe a race condition is occurring which the MessageBox is fixing somehow. Application A is starting Application B (the source code I have shown here) then sending a command line argument with some parameters into Application B. Without the MessageBox, Application A throws a TCP 10061 error.
Another point of interest, is there any easy way to debug WCF connections? I have access to the source of both applications, but I'm not sure if it is possible to have Application A launch Application B with the debugger (instead of just the executable). This would help immensely.
EDIT: Was playing around a bit more... found that if I use an Application.DoEvents()
instead of a messageBox, it's the same result.
来源:https://stackoverflow.com/questions/31949957/wcf-debugging-event-not-triggering-unless-messagebox-show-is-performed