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.
elseblock, there's no magic withMessageBoxnorApplication. Your problem is simply that theifcondition never evaluates true. UseEquals()with the proper string comparison option instead of==and inspect what is coming in by step debugging, you may need toTrim()as well.ifnever evaluates to true, how doesdoSomeStuffget executed then in either case? Also, I tried an emptyelsecondition and no go. I'm almost certain now the problem is with the GUI not updating in time which is why MessageBox (which calls on Application.DoEvents implicitly) and Application.DoEvents itself seemingly fixes the issue.Application.DoEventsoutside of the loop and if altogether, it fixes the issue as well.