Reputation: 437
I'm trying to fix an error in my code but it doesn't let me debug through a method. When I start debugging in the FormMain
it jumps to Program.cs
and skips the method that is called in the FormMain
. Can anyone suggest the cause of this
public FormMain() {
#if !DEBUG
//NativeMethods.BlockInput(true);
#endif
InitializeComponent();
var aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler((sender, e) => Execute());
aTimer.Interval = 120000;
aTimer.Enabled = true;
}
public void Execute() {
int Tijd;
int Videolengte;
string resultaat;
string URL = "";
Database db = new Database(CONNECTION_STRING);
object[] result = db.GetFirstRecord();
// if (result == null)
// {
// return;
// }
// else
// {
URL = (string)result[1];
Process browser = Process.Start(@"chrome.exe","http:\\www.youtube.com/watch?v=" + URL);
Audio.SetApplicationVolume(APP, 15);
resultaat = (string)result[2];
Videolengte = Convert.ToInt32(resultaat);
Tijd = Videolengte;
// Timer van afsluiten starten.
Upvotes: 0
Views: 107
Reputation: 13755
Your Execute()
method it's a callback method that it will be invoked later when the interval has elapsed for this reason uyou can't debug this method and it seems not to be called
aTimer.Elapsed += new ElapsedEventHandler((sender, e) => Execute());
put a breakpoint inside Execute()
and wait for 2 minutes
and your breakpoint will be hitted
public void Execute()
{ //here press F9 to set a breakpoint
int Tijd;
int Videolengte;
string resultaat;
string URL = "";
Another triks that may be usefull for you it's you must be sure that you mainform was launched using Application.Run(new MainForm);
which is a blocking call block meaning that your application will be alive untill you close your mainfom
Upvotes: 0
Reputation: 4173
Erm, that is normal...
The Main()
function in your Program.cs
is the entry point of the application. Therefor it starts debugging there when hitting F11.
Your Form FormMain
gets called after Program.cs
Just set a breakpoint where you need it in the FormMain and wait till it hits it while debugging. Start the debugging hitting F5 instead of F11
An interval of 120000 means it calls your function only each 2 minutes (120k milliseconds). You may want to set it to 5000 (5s) for debugging.
Upvotes: 2