Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
i don't know why its happening

i wrote a code to toggle play pause for vlc using hotkey and on pressing hotkey it repeats itself two time and thus nullify result.
C#
private void hotKeyPlayPause_HotKeyPressed(object sender, SmartHotKey.HotKeyEventArgs e)
        {
            if (videoLoaded)
            {
                if (playing)
                {
                    btnPause.Visible = false;
                    btnPlay.Visible = true;
                    playing = false;
                    axVLCPlugin1.pause();
                    return;
                }
                else
                {
                    btnPause.Visible = true;
                    btnPlay.Visible = false;
                    axVLCPlugin1.play();
                    playing = true;
                    return;
                }
            }
        }


When i try to debug this and create a breakpoint and follow F11 it shows that it first did pause() action up to return in if block and then jump back to check if(VideoLoaded) block... again enter in if/else block for toggle play pause and as usually this time it will execute else block as playing flag is false in second time execution...

any idea about this bug??? am i missing something???
Posted
Comments
[no name] 4-Aug-13 20:41pm    
Check the call stack to see where the event is being fired from.
Sergey Alexandrovich Kryukov 4-Aug-13 22:07pm    
This code sample would make sense if you showed also where the event handler is added to an invocation list of some event handler, that is, all relevant += operators.
—SA

You see, your statement is not accurate. You cannot say that your event is executes two times (events do not "execute"). What you see is that your event handler method is called two times, but this is nothing but a method, which can be called by different reasons.

First of all, check where the event handler is added to an invocation list of event instance, that is, all '+=' operators. Put a breakpoint on the first statement of the handler and run it under the debugger. When execution comes to the breakpoint, see the "Call Stack" window (under the "Debug" menu). It will show you where the call comes from in both cases.

—SA
 
Share this answer
 
Comments
Hitesh Rohilla 4-Aug-13 23:33pm    
First of all Sergey Alexanderovich Kryukov i have noticed too many time that you instead of answering just try to discuss some logical explanation on the topic... I think this is the only reason you have scored a lot here at codeproject... so thanks for your concerns and do not try to answer or rate my questions just for gaining scores... for general discussions and confirmations we have comment sections. I don't know if you think others are fool and haven't tried there code and just put there problems after first try only... whatever you are trying to explain i have checked already...

I know my words looks aggressive here but there is some point in it...

I have tried same code on two places for toggling purpose using a flag to toggle play/pause and for mute/un-mute and three more places just for some events increase volume, decrease volume, exit player... everywhere code works fine instead of places where it is used for toggling purpose. so event handlers are added properly is working fine that's why event is fired up. it is tested in debugging mode with breakpoints. yes method (not event) is called two time which is unwanted and that's why I raise my question here... logically there is no mistake in this.no such second calling is detected in call stack and that's why it is happening undauntedly.
Sergey Alexandrovich Kryukov 5-Aug-13 0:48am    
What do you mean "instead of answering"? This is an exact recipe or what you should be doing, a useful advice. No, your comments are not aggressive, but simply not not true and somewhat silly, I think. Even if you have tried already what I advised or already know some of my information, this is not a reason for baseless accusations. After all, you did not provide me with enough information, so I cannot know what did you try and what not. Just the opposite, you clearly demonstrated some lack of understanding.

Now, please follow my advice and get information. If you still cannot figure out what's going on and can provide more information, ask more...

—SA
Hitesh Rohilla 5-Aug-13 2:06am    
whatever sergey i just mentioned whatever i noticed an yes i may not provide information and you try to give advise but that's an advice not an answer to gain score... moreover you have down rate my questions without proper understanding what problems may i facing... which is fundamental right in this site weather valid or not... and by the way i am not concerning just this advice but have read more of your contents and found similar pattern. you may have more knowledge then me; i don't know you understand or not but you always try at least to attempt to answer and even if you just advice or discuss but you use less the comment utility more then you comment. it may be allegation but that's what i noticed.

secondly i have already mentioned that whatever you advised i have already followed... found no clue.
Sergey Alexandrovich Kryukov 5-Aug-13 10:25am    
If cannot give no clue by definition. Do I have to explain why? Well, let's say you think that one call is correct and another one is unwanted. Let's say, you press some key once and expect one call of the handler. You do it under the debugger and will see two calls. You either see only one call, but it would mean the problem does not exist. If you see two calls, it means one of them is parasitic. In both calls, you see all the stack. How it can possibly be no clue?
—SA
Sergey Alexandrovich Kryukov 5-Aug-13 10:28am    
And now, let me tell you this. I waste time on your question, having pretty little hope that you can actually understand and use it, because from all your question I can see that your skills and understanding is very low. And you are the one who is interested in solution, not me.

And even then, you keep meanly, meanly mumbling something about some idiotic "scores". Don't you feel any shame?

—SA
Be careful on which events you react: sometimes reacting to other events while reacting to an original event may cause confusion.
I think that axVLCPlugin1.pause(); causes another event. When the corresponding event handler is executed, you call again the handler for your hotkey, directly or indirectly.
 
Share this answer
 
Comments
Hitesh Rohilla 5-Aug-13 3:48am    
well if it is so then i cannot correct it as it is default method used by vlc (not created by me). is there any way to correct it?
i think the problem is with return can you just remove and check again?
 
Share this answer
 
Comments
Hitesh Rohilla 5-Aug-13 3:47am    
i have apply return in order to exit from current module directly after performing play or pause so that it will not call same module again. and i did this later on when face such problem. previously statement was without return; showing same behaviour

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900