Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging problem

Status
Not open for further replies.

Katy44

Technical User
Dec 12, 2003
723
0
0
GB
I have a windows app developed in C#.
My windows app does funny things in a specific situation and doesn't work as normal.
I have identified where in the code this funny thing happens and have stepped through it in a 'normal' situation. When I try to step through it in the 'funny' situation, it just cuts out, and the debugger takes me back to the "run application" command.
I tried putting the line of code in a try / catch, and using the catch to output the error, but it doesn't even catch the error - it just gets to that line and then cuts out in exactly the same way as before.
I know I haven't described any code, or exactly what the app does, as I'm hoping there's a general reason for this kind of debugging problem. Let me know if you do need to know specific details, and thanks in advance for any help.
 
The specific error occurs on the line
SendKeys.Send("{DOWN}");
 
If compiler execute a statement with errors and there is't a catch statement that catches that error then it goes to Application.Run line of main method. Try with System.Exception class of exception in the catch statement.
 
Thanks for your suggestion.
My code is:

Code:
try
					{
						SendKeys.Send("{DOWN}");							
						SendKeys.Send("{ENTER}");
						
					}
					catch(System.Exception p)
					{
						Console.WriteLine(p.Message.ToString());
					}
When I run the program, it all works and does what I want apart from one sutuation.
When I put the breakpoint on the first of the "SendKeys" statement, it steps over from the first statement to the second statement, but then just sort of hangs - step over does nothing and I have to kill my app to get anything to work.
I have events coming off a key press in the field - could that be why?
 
I've once simular problem to this. When I was in debug mode, when line like SendKeys.Send("{ENTER}") was executed, i lost contact with my VStudio. Then i press CTRL+ALT+Delete then Cancel and everything was fine. Then I desided to acomplish that behaviour differently. So the solution for me was insted of KeyPress event , to use ProcessDialogKey. Here is my code:
Code:
		protected override bool ProcessDialogKey(Keys keyData)
		{	
			switch (keyData)
			{
				case Keys.Enter:
					this.OnEnterKeyPressed();
					return base.ProcessDialogKey(Keys.Tab);
				case Keys.Add:
					this.OnPlusKeyPressed();
					return base.ProcessDialogKey(Keys.Tab);
				case Keys.Subtract:
					this.OnSubstractKeyPressed();
					return base.ProcessDialogKey(Keys.Shift | Keys.Tab);
				case Keys.Down:
					return base.ProcessDialogKey(Keys.Tab);
				case Keys.F3:
					this.OnF3KeyPressed();
					return true;
				case Keys.Shift | Keys.Escape:
					this.CausesValidation = false;
					base.ProcessDialogKey(Keys.Shift | Keys.Tab);
					this.CausesValidation = true;
					return true; 
			}
			return base.ProcessDialogKey(keyData);
		}
 
Thank you for that - it sounds like the same thing. I'll give the above a go to test the code.
Am I correct in thinking that you are overriding an existing method of the control? This sounds like a big change (the system is already in use and this is a bug fix). Could implementing your method cause other major problems? I'll definitely try it for testing though - it may help me to identify what is happening.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top