I've been thoroughly researching this and haven't been able to find what I need. I am currently working in an asp.net website, code behind being vb.net, and using a timer from system.timers.timer. I have created a page with two buttons, one to start my timer and one to stop my timer. They work mostly as I expect them to.
Here is my question: How do I make the timer stop when my program/site stops running? Not when I exit the browser, but when the actual program running my site stops? For example, when this goes live the program will be running on our server. I want the timer to always run in the background once I've clicked start, unless the site goes down or I click stop. In my development environment, when I click run and click my timer's start button, I want the timer to run until I either click stop or I stop debugging. The problem is that when I stop debugging the timer keeps running. How do I stop the timer when I stop debugging or, when live, the website stops(crashes)?
to stop your timer you have to detect that your application is still running or not and for that you have to write code in your global.asax file.
on Application_end event or may be in Application_EndRequest
for view how to use Global.asax file please review this link
http://www.codeproject.com/Articles/228879/Global-asax-in-ASP-NET
Please check this and try this code.
Thank you.
It looks like a task for a server side code: use Global.asax in this case
Related
I am debugging an ASP page with visual studio 2013.
So, i set a breakpoint, the breakpoint gets hit, and the execution gets on hold.
Now, i just want to abort the current request stop executing the code for the current request (which is on hold as it had hit the breakpoint), without having to stop debugging and run again the project.
This seems too simple, yet i haven't figured out how to do it.
Let me explicity state that clicking "restart" is not what i need, as "restart" is just a shortcut to stop project and run again.
Based on our conversation in the comments, I am placing this as an answer.
What you are asking for is not part of the visual studio debugging process. unless you manually return from the request after the break point the process is going to continue running. When debugging you are just an observer of the process. Either the code kills the process via exception or returns from execution, or you kill the process externally.
It does not looks like what you are asking for is possible, and that is by design.
I have my web app hosted on my local machine, and I try to debug it. I always use Attach to process to do this. BUT. Sometimes when I reach breakpoint and press F10 debugger just continue to run app as I press F5, so I can't go to next step. And sometimes I reattach to process and it runs ok, but not too long, some time pass it again do such strange things.
Can you explain why does it happens?
Regards, Dmitry.
I am developing an lib which tracks user events, like button click, state change, module load and application finish.
My problem is how I can track the application finish event. I googled for it, but I found no good answer.
It is possible to use this kind of event?
You need to use ExternalInterface, here is a good example:
Browser Window Close Event and Flex Applications
Using VS2008 on my local dev machine, when I run my asp.net Web Application project, it starts up a session of Asp.Net Development Server when I use F5 to run the app in debug mode. It all works fine and I can run my app for testing and such. Then, when I stop the running debugging instance of my app (by closing the IE window with the X close button, or by clicking the square Stop Debugging button in the VS IDE), the app stops and I return to the VS IDE, but it also closes down the Development Server session, and then, after I make a few edits to my code and want to run it again, it takes forever to launch up the Development Server again and serve up the first page of my very simple app.
Is it normal for the session of Asp.Net Development Server to completely shut down like this each time?
I only have 1 project in my solution, and it uses ADO.NET Typed DataSets and OLEDB adapters, and basic asp: controls in the aspx web form. Overall, it is a very small app.
I hate waiting 20-30 seconds each time I want to run my app just to see one tiny little code change.
I was also facing same problem, but in my case "Edit And Continue" setting was a culprit. Thanks for posting this.
If you don't need to debug every time, you can actually just open the URL outside of pressing F5 (press F5 once, copy the url, stop debugging, open it in a new browser). This way you can make any changes you want, recompile, and see it immediately. But as I said, it means you're not debugging. You don't always need to debug though.
A secondary option, is to run against IIS, and only attach to the process as needed.
I'm trying to debug a web service (Windows XP SP3, VS 2008, ASP.NET 2, VB.NET).
For most of it, if the asp.net worker process is already loaded, I can start the Windows form that calls the web service, attach to aspnet_wp.exe in Visual Studio, and then debug to my heart's content, but catching the Application Start event in global.asax is a pain.
If I reset IIS, of course there is no process to attach to, until the Application start event is all over.
The only way I've found to do this is create a separate aspx page, set it as the start page, and run that - then I can stop on the break in the App start event, but it's a nuisance having to maintain a page that's essentially just a test stub.
Any ideas for something a bit neater? Kind of, "Attach to a process as soon as it starts".
Better still, of course, would be not to have to attach explicitly to aspnet_wp.exe in order to be able to debug the web service, but I haven't found a way of doing that either.
Thanks for any suggestions.
Try sticking this in your Application Start event, it should kick your debugger everytime. Just make sure you take it out when you're done :-).
System.Diagnostics.Debugger.Launch()
Or better yet, in the OnStart of your WebService:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
System.Diagnostics.Debugger.Launch()
End Sub
Update: Adding this comment to the answer since it's a good idea:
Wrap this in #if DEBUG and it's a bit
safer (won't end up slipping something
so catastrophic into test/production
environments). – sliderhouserules