|
Thanks for your reply. But that code brings focus forcefully to the excel application which I dont want and Marshal.GetActiveObject() will not work in that case.
|
|
|
|
|
Hi
I have a timer which I've created in runtime with System.Timers.Timer myTimer = new System.Timers.Timer(10000);
I make some settings of this timer and start it with this code:
myTimer.Elapsed += new ElapsedEventHandler(myMethod);
myTimer.Start();
After myTimer started I stop myTimer using myTimer.Stop();
Some time later I need to start myTimer again so I start it with myTimer.Start(); But the weird thing is that it didn't actually stop when myTimer.Stop(); was executed. It's like two instances of myTimer are ticking at different times but I just want the last one to work.
How can I solve this problem?
Thanks in advance.
|
|
|
|
|
I think the code block where new ElapsedEventHandler is added is called more than once.
It means when even is raised, more than once the myMethod will be called, and hence the timer will be incremented.
|
|
|
|
|
So can I add more than one ElapsedEventHandler to my timer right?
If I
myTimer.Elapsed += new ElapsedEventHandler(Method1);
myTimer.Elapsed += new ElapsedEventHandler(Method2);
then when myTimer ticks both Method1 and Method2 runs, right?
If I
myTimer.Elapsed += new ElapsedEventHandler(Method);
myTimer.Elapsed += new ElapsedEventHandler(Method);
then when myTimer ticks Method will run twice, right?
|
|
|
|
|
|
Right, right and right again.
|
|
|
|
|
Thank you, then problem solved
|
|
|
|
|
Yes, but I doubt you want to do that; did you do that accidently?
|
|
|
|
|
|
So on every block I think it is better to do
myTimer.Elapsed -= new ElapsedEventHandler(Method);
myTimer.Elapsed += new ElapsedEventHandler(Method);
By this way even if this block is running more than one, everytime it will remove the eventhandler and then add it. Provided, if you are unsure that this block will run more than once.
|
|
|
|
|
Thank you, that is a nice way of doing it too.
But I solved it with adding a global int called Session with default value 0. And everytime I get this adding ElapsedEventHandler if this session is greater than 1 I don't add it.
|
|
|
|
|
yes .. this is a possible way...
nice to hear that you solved it.
Cheers.
|
|
|
|
|
Ummm... what? I didn't understand what you were trying to say.
What are you trying to accomplish and what problem are you having?
|
|
|
|
|
I had a timer which I stopped and started some time later. But when I started it for the second time it was doing what it was doing when ticked twice. It turned out that I was adding new eventhandler twice
|
|
|
|
|
So in the end this article[^] is about you?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Seems that way.
|
|
|
|
|
I've got simple console C# project that calls unmanaged DLL with Interop. I need to step into native DLL function either from C# or debug native DLL and break in C++ debugger.
I set up Enable unmanaged code debugging in C# console.
The DLL function is called correctly, e.g. it prints the message to console.
But as I run DLL with F5 and it invokes C# console, the break points do not work.
Nor can I step into DLL unmanaged code from C# console
Чесноков
|
|
|
|
|
|
that one worked, 'Enable just my code debugging'. Great!!!
Чесноков
|
|
|
|
|
however you still can not run native DLL which is invoked in C# and stop at bps in DLL project
Чесноков
|
|
|
|
|
I've got all setup as described and was debugging native DLL normally, while on the other project run it just stopped stepping into the native DLL?
What happened as I did not touched the settings they were before???
Чесноков
|
|
|
|
|
Hi, I have a small application that is exhibiting an AccessViolationException before it even enters Main(). I found this out after the pilot in our production environment started failing from time to time - it would enter some infinite loop somewhere at the end of Main() after all useful code has been executed. I found the access violation when running the app in the debugger.
The tricky bit is that it does not happen in controlled source code (the failure occurs before I reach Main()) so the actual issue is difficult to determine. I would suspect some kind of stack overflow but do to know how to troubleshoot this in Visual Studio. The app is in C#. Any suggestion to get started?
|
|
|
|
|
Maybe one more detail: it is a console app and is complaining about a Windows Form (in an attempt to issue a SendMessage()).
However, I do not have explicit instantiations of a Windows Form... Weird...
|
|
|
|
|
How about in project properties -> output type ?
It must be "Console Application".
|
|
|
|
|
It is. .NET target is also set to 2.0 for the production environment.
|
|
|
|